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


C# ConstructorInfo.GetMethodHandle方法代码示例

本文整理汇总了C#中System.Reflection.ConstructorInfo.GetMethodHandle方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInfo.GetMethodHandle方法的具体用法?C# ConstructorInfo.GetMethodHandle怎么用?C# ConstructorInfo.GetMethodHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.ConstructorInfo的用法示例。


在下文中一共展示了ConstructorInfo.GetMethodHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InternalGetConstructorToken

        internal MethodToken InternalGetConstructorToken(ConstructorInfo con, bool usingRef)
        {
            // Helper to get constructor token. If usingRef is true, we will never use the def token
 
            
            int tr;
            int mr = 0;
            
            if (con == null)
                throw new ArgumentNullException("con");

            if (con is ConstructorBuilder)
            {
                ConstructorBuilder conBuilder = con as ConstructorBuilder;
                if (usingRef == false && conBuilder.ReflectedType.Module.Equals(this))
                    return conBuilder.GetToken();

                // constructor is defined in a different module
                tr = GetTypeToken(con.ReflectedType).Token;
                mr = InternalGetMemberRef(con.ReflectedType.Module, tr, conBuilder.GetToken().Token);
            }
            else if (con is ConstructorOnTypeBuilderInstantiation)
            {
                ConstructorOnTypeBuilderInstantiation conBuilder = con as ConstructorOnTypeBuilderInstantiation;
                if (usingRef == true) throw new InvalidOperationException();

                tr = GetTypeToken(con.DeclaringType).Token;
                mr = InternalGetMemberRef(con.DeclaringType.Module, tr, conBuilder.m_ctor.MetadataTokenInternal);
            }
            else if (con is RuntimeConstructorInfo && con.ReflectedType.IsArray == false)
            {
                // constructor is not a dynamic field
                // We need to get the TypeRef tokens

                tr = GetTypeToken(con.ReflectedType).Token;
                mr = InternalGetMemberRefOfMethodInfo(tr, con.GetMethodHandle());
            }
            else
            {
                // some user derived ConstructorInfo
                // go through the slower code path, i.e. retrieve parameters and form signature helper.
                ParameterInfo[] parameters = con.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(con.ReflectedType).Token;

                SignatureHelper sigHelp = SignatureHelper.GetMethodSigHelper(this, con.CallingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers);
                int length;
                byte[] sigBytes = sigHelp.InternalGetSignature(out length);

                mr = InternalGetMemberRefFromSignature(tr, con.Name, sigBytes, length);
            }
            
            return new MethodToken( mr );
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:64,代码来源:modulebuilder.cs


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