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


C# MethodBase.GetParameterTypes方法代码示例

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


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

示例1: GetMethodArgumentInformation

        private static string GetMethodArgumentInformation(MethodBase method, Assembly containingAssembly)
        {
            var info = new StringBuilder();

            info.Append("(");
            var num = 0;

            var argumentTypes = method.GetParameterTypes();

            if(argumentTypes.Length > 0)
            {
                var list = new List<string>();
                var methodParameterDeclarationNames = method.GetGenericParameterDeclarationNames();

                foreach(var type in argumentTypes)
                {
                    var arguments = new List<string>();

                    var elementType = type.GetRootElementType();

                    if(elementType.IsGenericParameter)
                    {
                        if(methodParameterDeclarationNames.Contains(elementType.Name))
                        {
                            arguments.Add("!!" + type.Name);
                        }
                        else
                        {
                            arguments.Add("!" + type.Name);
                        }
                    }
                    else
                    {
                        arguments.Add(new TypeDescriptor(type, containingAssembly).Value);
                    }

                    arguments.Add("V_" + num.ToString(CultureInfo.CurrentCulture));
                    list.Add(string.Join(" ", arguments.ToArray()));

                    num++;
                }
                info.Append(string.Join(", ", list.ToArray()));
            }

            info.Append(")");

            return info.ToString();
        }
开发者ID:JasonBock,项目名称:EmitDebugging,代码行数:48,代码来源:MethodGenericDeclarationDescriptor.cs

示例2: GetMemberRefToken

        [System.Security.SecurityCritical]  // auto-generated
        private int GetMemberRefToken(MethodBase method, IEnumerable<Type> optionalParameterTypes)
        {
            Type[] parameterTypes;
            Type returnType;
            int tkParent;
            int cGenericParameters = 0;

            if (method.IsGenericMethod)
            {
                if (!method.IsGenericMethodDefinition)
                    throw new InvalidOperationException();

                cGenericParameters = method.GetGenericArguments().Length;
            }

            if (optionalParameterTypes != null)
            {
                if ((method.CallingConvention & CallingConventions.VarArgs) == 0)
                {
                    // Client should not supply optional parameter in default calling convention
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
                }
            }

            MethodInfo masmi = method as MethodInfo;

            if (method.DeclaringType.IsGenericType)
            {
                MethodBase methDef = null; // methodInfo = G<Foo>.M<Bar> ==> methDef = G<T>.M<S>

                MethodOnTypeBuilderInstantiation motbi;
                ConstructorOnTypeBuilderInstantiation cotbi;

                if ((motbi = method as MethodOnTypeBuilderInstantiation) != null)
                {
                    methDef = motbi.m_method;
                }
                else if ((cotbi = method as ConstructorOnTypeBuilderInstantiation) != null)
                {
                    methDef = cotbi.m_ctor;
                }
                else if (method is MethodBuilder || method is ConstructorBuilder)
                {
                    // methodInfo must be GenericMethodDefinition; trying to emit G<?>.M<S>
                    methDef = method;
                }
                else
                {
                    Contract.Assert(method is RuntimeMethodInfo || method is RuntimeConstructorInfo);

                    if (method.IsGenericMethod)
                    {
                        Contract.Assert(masmi != null);

                        methDef = masmi.GetGenericMethodDefinition();
                        methDef = methDef.Module.ResolveMethod(
                            method.MetadataToken,
                            methDef.DeclaringType != null ? methDef.DeclaringType.GetGenericArguments() : null,
                            methDef.GetGenericArguments());
                    }
                    else
                    {
                        methDef = method.Module.ResolveMethod(
                            method.MetadataToken,
                            method.DeclaringType != null ? method.DeclaringType.GetGenericArguments() : null,
                            null);
                    }
                }

                parameterTypes = methDef.GetParameterTypes();
                returnType = MethodBuilder.GetMethodBaseReturnType(methDef);
            }
            else
            {
                parameterTypes = method.GetParameterTypes();
                returnType = MethodBuilder.GetMethodBaseReturnType(method);
            }

            int sigLength;
            byte[] sigBytes = GetMemberRefSignature(method.CallingConvention, returnType, parameterTypes,
                optionalParameterTypes, cGenericParameters).InternalGetSignature(out sigLength);

            if (method.DeclaringType.IsGenericType)
            {
                int length;
                byte[] sig = SignatureHelper.GetTypeSigToken(this, method.DeclaringType).InternalGetSignature(out length);
                tkParent = GetTokenFromTypeSpec(sig, length);
            }
            else if (!method.Module.Equals(this))
            {
                // Use typeRef as parent because the method's declaringType lives in a different assembly                
                tkParent = GetTypeToken(method.DeclaringType).Token;
            }
            else
            {
                // Use methodDef as parent because the method lives in this assembly and its declaringType has no generic arguments
                if (masmi != null)
                    tkParent = GetMethodToken(masmi).Token;
                else
//.........这里部分代码省略.........
开发者ID:crummel,项目名称:dotnet_coreclr,代码行数:101,代码来源:ModuleBuilder.cs

示例3: GetMethodArgumentInformation

        private static string GetMethodArgumentInformation(MethodBase method, Assembly containingAssembly, bool isDeclaration)
        {
            var information = new StringBuilder();

            information.Append("(");
            var i = 0;

            var argumentTypes = method.GetParameterTypes();

            if(argumentTypes.Length > 0)
            {
                var descriptors = new List<string>();

                foreach(var type in argumentTypes)
                {
                    var argumentDescriptor = new List<string>() {
                        new TypeDescriptor(type, containingAssembly).Value
                    };

                    if(isDeclaration)
                    {
                        argumentDescriptor.Add("V_" + i.ToString(CultureInfo.CurrentCulture));
                    }

                    descriptors.Add(string.Join(" ", argumentDescriptor.ToArray()));

                    i++;
                }

                if(!isDeclaration &&
                    ((method.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs))
                {
                    descriptors.Add("...");
                }

                information.Append(string.Join(", ", descriptors.ToArray()));
            }

            information.Append(")");
            return information.ToString();
        }
开发者ID:JasonBock,项目名称:EmitDebugging,代码行数:41,代码来源:MethodDescriptor.cs

示例4: GetMemberRefToken

 internal int GetMemberRefToken(MethodBase method, Type[] optionalParameterTypes)
 {
     Type[] parameterTypes;
     Type methodBaseReturnType;
     int tokenFromTypeSpec;
     int num4;
     int cGenericParameters = 0;
     if (method.IsGenericMethod)
     {
         if (!method.IsGenericMethodDefinition)
         {
             throw new InvalidOperationException();
         }
         cGenericParameters = method.GetGenericArguments().Length;
     }
     if ((optionalParameterTypes != null) && ((method.CallingConvention & CallingConventions.VarArgs) == 0))
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
     }
     MethodInfo info = method as MethodInfo;
     if (method.DeclaringType.IsGenericType)
     {
         MethodBase ctor = null;
         MethodOnTypeBuilderInstantiation instantiation = method as MethodOnTypeBuilderInstantiation;
         if (instantiation != null)
         {
             ctor = instantiation.m_method;
         }
         else
         {
             ConstructorOnTypeBuilderInstantiation instantiation2 = method as ConstructorOnTypeBuilderInstantiation;
             if (instantiation2 != null)
             {
                 ctor = instantiation2.m_ctor;
             }
             else if ((method is MethodBuilder) || (method is ConstructorBuilder))
             {
                 ctor = method;
             }
             else if (method.IsGenericMethod)
             {
                 ctor = info.GetGenericMethodDefinition();
                 ctor = ctor.Module.ResolveMethod(method.MetadataToken, (ctor.DeclaringType != null) ? ctor.DeclaringType.GetGenericArguments() : null, ctor.GetGenericArguments());
             }
             else
             {
                 ctor = method.Module.ResolveMethod(method.MetadataToken, (method.DeclaringType != null) ? method.DeclaringType.GetGenericArguments() : null, null);
             }
         }
         parameterTypes = ctor.GetParameterTypes();
         methodBaseReturnType = MethodBuilder.GetMethodBaseReturnType(ctor);
     }
     else
     {
         parameterTypes = method.GetParameterTypes();
         methodBaseReturnType = MethodBuilder.GetMethodBaseReturnType(method);
     }
     if (method.DeclaringType.IsGenericType)
     {
         int num3;
         byte[] buffer = SignatureHelper.GetTypeSigToken(this, method.DeclaringType).InternalGetSignature(out num3);
         tokenFromTypeSpec = this.GetTokenFromTypeSpec(buffer, num3);
     }
     else if (!method.Module.Equals(this))
     {
         tokenFromTypeSpec = this.GetTypeToken(method.DeclaringType).Token;
     }
     else if (info != null)
     {
         tokenFromTypeSpec = this.GetMethodToken(info).Token;
     }
     else
     {
         tokenFromTypeSpec = this.GetConstructorToken(method as ConstructorInfo).Token;
     }
     byte[] signature = this.GetMemberRefSignature(method.CallingConvention, methodBaseReturnType, parameterTypes, optionalParameterTypes, cGenericParameters).InternalGetSignature(out num4);
     return this.GetMemberRefFromSignature(tokenFromTypeSpec, method.Name, signature, num4);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:78,代码来源:ModuleBuilder.cs

示例5: Get

			public override ImmutableArray<Type> Get( MethodBase parameter ) => base.Get( parameter ).Union( parameter.GetParameterTypes().AsEnumerable() ).ToImmutableArray();
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:1,代码来源:IncludeParameterTypesAttribute.cs

示例6: GetMemberRefToken

        internal virtual int GetMemberRefToken(MethodBase method, Type[] optionalParameterTypes)
        {
            Type[] parameterTypes;
            Type returnType;
            int tkParent;
            ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
            int cGenericParameters = 0;

            if (method.IsGenericMethod)
            {
                if (!method.IsGenericMethodDefinition)
                    throw new InvalidOperationException();
            
                cGenericParameters = method.GetGenericArguments().Length;
            }

            if (optionalParameterTypes != null)
            {
                if ((method.CallingConvention & CallingConventions.VarArgs) == 0)
                {
                    // Client should not supply optional parameter in default calling convention
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
                }
            }

            if (method.DeclaringType.IsGenericType)
            {
                MethodBase methDef = null; // methodInfo = G<Foo>.M<Bar> ==> methDef = G<T>.M<S>
                
                if (method is MethodOnTypeBuilderInstantiation)
                {
                    methDef = (method as MethodOnTypeBuilderInstantiation).m_method;
                }
                else if (method is ConstructorOnTypeBuilderInstantiation)
                {
                    methDef = (method as ConstructorOnTypeBuilderInstantiation).m_ctor;
                }
                else if (method is MethodBuilder || method is ConstructorBuilder)
                {
                    // methodInfo must be GenericMethodDefinition; trying to emit G<?>.M<S>
                    methDef = method;
                }
                else if (method.IsGenericMethod)
                {
                    methDef = ((MethodInfo)method).GetGenericMethodDefinition();
                    methDef = methDef.Module.ResolveMethod(
                        methDef.MetadataTokenInternal, 
                        methDef.GetGenericArguments(), 
                        methDef.DeclaringType != null ? methDef.DeclaringType.GetGenericArguments() : null) as MethodBase;
                }
                else
                {
                    methDef = method;
                    methDef = method.Module.ResolveMethod(
                        method.MetadataTokenInternal, 
                        null, 
                        methDef.DeclaringType != null ? methDef.DeclaringType.GetGenericArguments() : null) as MethodBase;
                }

                parameterTypes = methDef.GetParameterTypes();
                returnType = methDef.GetReturnType();
            }
            else
            {
                parameterTypes = method.GetParameterTypes();
                returnType = method.GetReturnType();
            }

            if (method.DeclaringType.IsGenericType)
            {
                int length;
                byte[] sig = SignatureHelper.GetTypeSigToken(modBuilder, method.DeclaringType).InternalGetSignature(out length);
                tkParent = modBuilder.InternalGetTypeSpecTokenWithBytes(sig, length);
            }
            else if (method.Module != modBuilder)
            {                
                // Use typeRef as parent because the method's declaringType lives in a different assembly                
                tkParent = modBuilder.GetTypeToken(method.DeclaringType).Token;
            }
            else
            {
                // Use methodDef as parent because the method lives in this assembly and its declaringType has no generic arguments
                if (method is MethodInfo)
                    tkParent = modBuilder.GetMethodToken(method as MethodInfo).Token;
                else
                    tkParent = modBuilder.GetConstructorToken(method as ConstructorInfo).Token;
            }

            int sigLength;
            byte[] sigBytes = GetMemberRefSignature(
                method.CallingConvention, returnType, parameterTypes, 
                optionalParameterTypes, cGenericParameters).InternalGetSignature(out sigLength); 

            return modBuilder.InternalGetMemberRefFromSignature(tkParent, method.Name, sigBytes, sigLength);
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:95,代码来源:ilgenerator.cs


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