> methodBaseList = new List<MethodBase>(constructors.Length); Type[] argumentTypes = new ) constructors[index]); } MethodBase[] methodBaseArray = new MethodBase[methodBaseList.Count = null && methodBaseArray.Length == 0) methodBaseArray = (MethodBase[]) null; methodBase; try { methodBase = binder.BindToMethod(bindingAttr = (MethodBase) null; } if (methodBase == (MethodBase) null) {
: Attribute { } public class Log : WeaveAction { public static void OnActionBefore(MethodBase 方法引用 var mfReference=assembly.MainModule.Import(typeof (System.Reflection.MethodBase maxstack 1 .locals init ( [0] string str) L_0000: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetCurrentMethod() L_0005: call void TestLibrary.Log::OnActionBefore (class [mscorlib]System.Reflection.MethodBase) L_000a: nop L_000b: ldstr "Vidar" L_0010:
summary> public static class MethodTimeLogger1 { public static void Log(MethodBase methodBase, long milliseconds, string message) { Console.WriteLine($"方法: {methodBase.Name} 耗时:{milliseconds} 毫秒,信息:{message}"); } } 运行耗时为TimeSpan: methodBase, TimeSpan elapsed, string message) { Console.WriteLine($"方法:{ methodBase.Name} 耗时:{elapsed.TotalMilliseconds} 毫秒,信息:{message}"); } } 耗时统计时长输出
$"输出结果{i}"); } } finally { stopwatch.Stop(); string message = null; MethodTimeLogger.Log(MethodBase.GetMethodFromHandle public static class MethodTimeLogger1 { public static void Log(MethodBase methodBase, long milliseconds, string message) { Console.WriteLine($"方法:{methodBase.Name / public static class MethodTimeLogger { public static void Log(MethodBase methodBase, TimeSpan elapsed, string message) { Console.WriteLine($"方法:{methodBase.Name
{ //增加其他日志类型,处理方案如下 //无论是否需记录log_method方法,方法均先执行完成.同时,记录时执行时间 MethodBase mbCurrent = input.MethodBase; string methodName = input.MethodBase.Name; string = null ) { string declaringType = input.MethodBase.ToString(); string instanceName = input.MethodBase.Module.Name; //获取参数列表 Dictionary for (int u = 0; u < sfs.Length; ++u) { System.Reflection.MethodBase
." + MethodBase.GetCurrentMethod().Name); } protected override void OnStart() { base.OnStart(); Android.Util.Log.Debug("Debug", this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name); } void OnResume() { base.OnResume(); Android.Util.Log.Debug("Debug", this.GetType().Name + "." + MethodBase.GetCurrentMethod void OnRestart() { base.OnRestart(); Android.Util.Log.Debug("Debug", this.GetType().Name + "." + MethodBase.GetCurrentMethod void OnDestroy() { base.OnDestroy(); Android.Util.Log.Debug("Debug", this.GetType().Name + "." + MethodBase.GetCurrentMethod
private static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger(); public static void Log(MethodBase methodBase, TimeSpan elapsed, string message) { _logger.Debug($"{methodBase.Name}, {elapsed
(_methodBase is MethodInfo)) { IRuntimeMethodInfo method = FindMethodHandle .ParameterType; } } } _methodBase } else if (IsUnmanagedFunctionPtr()) { if ((_methodBase (_methodBase is MethodInfo)) { IRuntimeMethodInfo method = FindMethodHandle declaringType = reflectedType; } _methodBase
through method handle check } // method ptrs don't match, go down long path // if (_methodBase _methodBase == null || !(_methodBase is MethodInfo) || !(d. _methodBase is MethodInfo)) return Delegate.InternalEqualMethodHandles(this, d); else return _methodBase.Equals(d. _methodBase); } 于是可以看出来,判断相等就是两个关键对象的判断相等: 方法所在的对象 方法信息(对应到反射里的 MethodInfo) 继续回到这段代码: 1 2 3 4 5 6 7
有多种方法可以获取Logger对象,经过实验,使用下面的方法可以适用于普通类和静态类的输出: log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod { (new Thread(test)).Start(); } } void test() { log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod info); } public static void Info(String info) { log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod info); } public static void Error(String info) { log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod info); } public static void Fatal(String info) { log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
callMessageWrapper = new MethodCallMessageWrapper((IMethodCallMessage) msg); MethodInfo methodBase = callMessageWrapper.MethodBase as MethodInfo; if (methodBase == null) argumentTypeList = Type.EmptyTypes; } var method = type.GetMethod(methodBase.Name (method == null) { throw new ArgumentException("调用方法不匹配,找不到" + methodBase
param>
/// <param name="method"></param>
public CustomerExceptionEvent(Exception ex, MethodBase param name="method"></param>
public CustomerExceptionEvent(Exception ex, string actionRoute, MethodBase summary>
/// 当前出现位置
/// <example>
///
/// MethodInfo = (MethodInfo)MethodBase.GetCurrentMethod new CustomerExceptionEvent(ex, MethodBase.GetCurrentMethod());
...
}
MethodBase.GetCurrentMethod
而对Target object的调用实际上是通过Reflection的方式调用的(callMessage.MethodBase.Invoke)。 public class InterceptingRealProxy : RealProxy, IRemotingTypeInfo 2: { 3: private Dictionary<MethodBase Target { get; } 13: public string TypeName { get; set; } 14: } 上面是它所有的成员定义,其中memberHandlers是一个以MethodBase )) 6: { 7: pipeline = this.memberHandlers[callMessage.MethodBase]; 8: } 9 总的来说上面的Code现根据msg解析出MethodBase,再获取对应的CallHandler Pipeline,最后调用Pipeline。
} } object o = callMsg.MethodBase.Invoke = null) { var methodInfo = args.MethodCall.MethodBase as MethodInfo; = null) { var methodInfo = args.MethodCall.MethodBase as MethodInfo; = null) { var methodInfo = args.MethodCall.MethodBase as MethodInfo; { var methodCall = msg as IMethodCallMessage; var methodInfo = methodCall.MethodBase
reader.ReadToEnd(); reader.Close(); } log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod content.Length.ToString()); } catch (Exception ex) { log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
Debug.Assert(new Foobar().Invoke() == 1); Debug.Assert(Indicator.Injected == true); } static MethodBase MonoMod.Common包中),并在方法体的前面添加了两个IL指令将Indicator的Injected属性设置为True,该方法最终返回通过这个DynamicMethodDefinition对象生成的MethodBase 和第一种方案一样,我们的代理对象依旧是封装目标对象,在实现的Invoke方案中,我们利用作为参数的IMessage 方法得到代表目标方法的MethodBase对象,进而利用它实现针对目标方法的调用。 methodCall.Args.CopyTo(copiedArgs, 0); try { object returnValue = methodCall.MethodBase.Invoke
=null) { var methodInfo = methodMsg.MethodBase as MethodInfo; = null) { Interceptor.BeforeEvent(methodMsg.MethodBase, methodMsg.InArgs ); } var result= methodMsg.MethodBase.Invoke(Instance, methodMsg.InArgs = null) { Interceptor.AfterEvent(methodMsg.MethodBase, result = null) { Interceptor.ExceptionEvent(ex, methodMsg.MethodBase);
Attributes public abstract Type BaseType public virtual bool ContainsGenericParameters public virtual MethodBase virtual object GetValue(object obj, object[] index) public void SetValue(object obj, object value) 分析MethodBase bool IsPublic public bool IsSpecialName public bool IsStatic public bool IsVirtual 方法: public static MethodBase
void TaskOne() { Console.WriteLine($"任务{Task.CurrentId},方法名:{System.Reflection.MethodBase.GetCurrentMethod Task.Delay(1000).Wait(); Console.WriteLine($"任务{Task.CurrentId},方法名:{System.Reflection.MethodBase.GetCurrentMethod task.Id}以及结束了"); Console.WriteLine($"现在开始的 任务是任务{Task.CurrentId},方法名称:{System.Reflection.MethodBase.GetCurrentMethod task.Id}以及结束了"); Console.WriteLine($"现在开始的 任务是任务{Task.CurrentId}.方法名称:{System.Reflection.MethodBase.GetCurrentMethod
Debug.Assert(new Foobar().Invoke() == 1); Debug.Assert(Indicator.Injected == true); } static MethodBase MonoMod.Common包中),并在方法体的前面添加了两个IL指令将Indicator的Injected属性设置为True,该方法最终返回通过这个DynamicMethodDefinition对象生成的MethodBase 和第一种方案一样,我们的代理对象依旧是封装目标对象,在实现的Invoke方案中,我们利用作为参数的IMessage 方法得到代表目标方法的MethodBase对象,进而利用它实现针对目标方法的调用。 methodCall.Args.CopyTo(copiedArgs, 0); try { object returnValue = methodCall.MethodBase.Invoke