本文整理汇总了C#中System.Reflection.MethodInfo.GetMethodHandle方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetMethodHandle方法的具体用法?C# MethodInfo.GetMethodHandle怎么用?C# MethodInfo.GetMethodHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetMethodHandle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StandardAdvice
/*----------------------------------------------------------------------------------------*/
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="StandardAdvice"/> class.
/// </summary>
/// <param name="method">The method that will be intercepted.</param>
public StandardAdvice(MethodInfo method)
{
Ensure.ArgumentNotNull(method, "method");
MethodHandle = method.GetMethodHandle();
}
示例2: NumParamBytes
public static int NumParamBytes(MethodInfo m)
{
if (m == null)
throw new ArgumentNullException("m");
if (!(m is RuntimeMethodInfo))
throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"));
RuntimeMethodHandle method = m.GetMethodHandle();
return InternalNumParamBytes(method.Value);
}
示例3: Advice
/// <summary>
/// Initializes a new instance of the <see cref="Advice"/> class.
/// </summary>
/// <param name="method">The method that will be intercepted.</param>
public Advice( MethodInfo method )
{
Ensure.ArgumentNotNull( method, "method" );
MethodHandle = method.GetMethodHandle();
this.method = method;
}
示例4: GetMethodTokenNoLock
private MethodToken GetMethodTokenNoLock(MethodInfo method)
{
// Return a MemberRef token if MethodInfo is not defined in this module. Or
// return the MethodDef token.
int tr;
int mr = 0;
if (method == null)
throw new ArgumentNullException("method");
if (method is MethodBuilder || method is MethodOnTypeBuilderInstantiation)
{
if (method.Module == this)
return new MethodToken(method.MetadataTokenInternal);
if (method.DeclaringType == null)
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
// method is defined in a different module
tr = GetTypeToken(method.DeclaringType).Token;
mr = InternalGetMemberRef(method.DeclaringType.Module, tr, method.MetadataTokenInternal);
}
else if (method is SymbolMethod)
{
SymbolMethod symMethod = method as SymbolMethod;
if (symMethod.GetModule() == this)
return symMethod.GetToken();
// form the method token
return symMethod.GetToken(this);
}
else
{
Type declaringType = method.DeclaringType;
// We need to get the TypeRef tokens
if (declaringType == null)
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
if (declaringType.IsArray == true)
{
// use reflection to build signature to work around the E_T_VAR problem in EEClass
ParameterInfo[] paramInfo = method.GetParameters();
Type[] tt = new Type[paramInfo.Length];
for (int i = 0; i < paramInfo.Length; i++)
tt[i] = paramInfo[i].ParameterType;
return GetArrayMethodToken(declaringType, method.Name, method.CallingConvention, method.ReturnType, tt);
}
else if (method is RuntimeMethodInfo)
{
tr = GetTypeToken(declaringType).Token;
mr = InternalGetMemberRefOfMethodInfo(tr, method.GetMethodHandle());
}
else
{
// some user derived ConstructorInfo
// go through the slower code path, i.e. retrieve parameters and form signature helper.
ParameterInfo[] parameters = method.GetParameters();
Type[] parameterTypes = new Type[parameters.Length];
Type[][] requiredCustomModifiers = new Type[parameterTypes.Length][];
Type[][] optionalCustomModifiers = new Type[parameterTypes.Length][];
for (int i = 0; i < parameters.Length; i++)
{
parameterTypes[i] = parameters[i].ParameterType;
requiredCustomModifiers[i] = parameters[i].GetRequiredCustomModifiers();
optionalCustomModifiers[i] = parameters[i].GetOptionalCustomModifiers();
}
tr = GetTypeToken(method.ReflectedType).Token;
SignatureHelper sigHelp;
try
{
sigHelp = SignatureHelper.GetMethodSigHelper(
this, method.CallingConvention, method.ReturnType,
method.ReturnParameter.GetRequiredCustomModifiers(), method.ReturnParameter.GetOptionalCustomModifiers(),
parameterTypes, requiredCustomModifiers, optionalCustomModifiers);
}
catch(NotImplementedException)
{
// Legacy code deriving from MethodInfo may not have implemented ReturnParameter.
sigHelp = SignatureHelper.GetMethodSigHelper(this, method.ReturnType, parameterTypes);
}
int length;
byte[] sigBytes = sigHelp.InternalGetSignature(out length);
mr = InternalGetMemberRefFromSignature(tr, method.Name, sigBytes, length);
}
}
return new MethodToken(mr);
}