当前位置: 首页>>代码示例>>C#>>正文


C# MethodInfo.GetMethodHandle方法代码示例

本文整理汇总了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();
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:11,代码来源:StandardAdvice.cs

示例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);
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:12,代码来源:marshal.cs

示例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;
 }
开发者ID:njmube,项目名称:Ninject.Extensions.Interception,代码行数:10,代码来源:Advice.cs

示例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);
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:100,代码来源:modulebuilder.cs


注:本文中的System.Reflection.MethodInfo.GetMethodHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。