本文整理汇总了C#中System.Diagnostics.StackFrame.?.GetFileName方法的典型用法代码示例。如果您正苦于以下问题:C# StackFrame.?.GetFileName方法的具体用法?C# StackFrame.?.GetFileName怎么用?C# StackFrame.?.GetFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackFrame
的用法示例。
在下文中一共展示了StackFrame.?.GetFileName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMethodFrame
public static Action<Binding[], int> CreateMethodFrame(string description, StackFrame frame)
{
lock (Module)
{
const string methodName = " ";
var className = description;
if (ClassNames.Contains(className))
{
className += " /" + ClassNames.Count;
}
ClassNames.Add(className);
var type = Module.DefineType(className, TypeAttributes.Class | TypeAttributes.Public);
var method = type.DefineMethod(methodName, MethodAttributes.Public | MethodAttributes.Static, typeof(void), new[] { typeof(Binding[]), typeof(int) });
method.SetImplementationFlags(MethodImplAttributes.NoOptimization);
var il = method.GetILGenerator();
var binding = il.DeclareLocal(typeof(Binding));
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldelem_I4);
il.Emit(OpCodes.Stloc_S, binding);
var fileName = frame?.GetFileName();
if (!string.IsNullOrEmpty(fileName))
{
var symbolDocument = Module.DefineDocument(fileName, SymDocumentType.Text, SymLanguageType.CSharp, SymLanguageVendor.Microsoft);
il.MarkSequencePoint(symbolDocument, frame.GetFileLineNumber(), frame.GetFileColumnNumber(), frame.GetFileLineNumber(), frame.GetFileColumnNumber() + 2);
method.DefineParameter(1, ParameterAttributes.None, "bindings");
method.DefineParameter(2, ParameterAttributes.None, "index");
}
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof(Binding[]).GetProperty("Length").GetGetMethod());
il.Emit(OpCodes.Ldc_I4_1);
il.Emit(OpCodes.Sub);
var lblFin = il.DefineLabel();
il.Emit(OpCodes.Bge_S, lblFin);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldc_I4_1);
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Ldelem_I4);
il.Emit(OpCodes.Ldfld, typeof(Binding).GetField("DebugContext"));
il.Emit(OpCodes.Callvirt, typeof(DebugContext).GetProperty("VirtualFrame").GetGetMethod());
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldc_I4_1);
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Call, typeof(Action<Binding[], int>).GetMethod("Invoke"));
il.Emit(OpCodes.Ret);
il.MarkLabel(lblFin);
il.Emit(OpCodes.Ldloc, binding);
il.Emit(OpCodes.Callvirt, typeof(Binding).GetMethod("Execute"));
il.Emit(OpCodes.Ret);
if (!string.IsNullOrEmpty(fileName))
{
binding.SetLocalSymInfo("binding", 0, il.ILOffset);
}
var actualType = type.CreateType();
return (Action<Binding[], int>)actualType.GetMethod(methodName).CreateDelegate(typeof(Action<Binding[], int>));
}
}