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


C# MethodBase.GetMethodHandle方法代码示例

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


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

示例1: GetParameters

 internal static unsafe ParameterInfo[] GetParameters(MethodBase method, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
 {
     RuntimeMethodHandle methodHandle = method.GetMethodHandle();
     returnParameter = null;
     int length = sig.Arguments.Length;
     ParameterInfo[] infoArray = fetchReturnParameter ? null : new ParameterInfo[length];
     int methodDef = methodHandle.GetMethodDef();
     int count = 0;
     if (!System.Reflection.MetadataToken.IsNullToken(methodDef))
     {
         MetadataImport metadataImport = methodHandle.GetDeclaringType().GetModuleHandle().GetMetadataImport();
         count = metadataImport.EnumParamsCount(methodDef);
         int* result = stackalloc int[count];
         metadataImport.EnumParams(methodDef, result, count);
         for (uint i = 0; i < count; i++)
         {
             ParameterAttributes attributes;
             int num5;
             int parameterToken = result[(int) ((int*) i)];
             metadataImport.GetParamDefProps(parameterToken, out num5, out attributes);
             num5--;
             if (fetchReturnParameter && (num5 == -1))
             {
                 returnParameter = new ParameterInfo(sig, metadataImport, parameterToken, num5, attributes, member);
             }
             else if (!fetchReturnParameter && (num5 >= 0))
             {
                 infoArray[num5] = new ParameterInfo(sig, metadataImport, parameterToken, num5, attributes, member);
             }
         }
     }
     if (fetchReturnParameter)
     {
         if (returnParameter == null)
         {
             returnParameter = new ParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, ParameterAttributes.None, member);
         }
         return infoArray;
     }
     if (count < (infoArray.Length + 1))
     {
         for (int j = 0; j < infoArray.Length; j++)
         {
             if (infoArray[j] == null)
             {
                 infoArray[j] = new ParameterInfo(sig, MetadataImport.EmptyImport, 0, j, ParameterAttributes.None, member);
             }
         }
     }
     return infoArray;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:51,代码来源:ParameterInfo.cs

示例2: GetParameters

        internal unsafe static ParameterInfo[] GetParameters(
            MethodBase method, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
        {
            RuntimeMethodHandle methodHandle = method.GetMethodHandle();
            returnParameter = null;
            int sigArgCount = sig.Arguments.Length;
            ParameterInfo[] args = fetchReturnParameter ? null : new ParameterInfo[sigArgCount];

            int tkMethodDef = methodHandle.GetMethodDef();
            int cParamDefs = 0;

            // Not all methods have tokens. Arrays, pointers and byRef types do not have tokens as they
            // are generated on the fly by the runtime. 
            if (!MdToken.IsNullToken(tkMethodDef))
            {
                MetadataImport scope = methodHandle.GetDeclaringType().GetModuleHandle().GetMetadataImport();
                cParamDefs = scope.EnumParamsCount(tkMethodDef);
                int* tkParamDefs = stackalloc int[cParamDefs];
                scope.EnumParams(tkMethodDef, tkParamDefs, cParamDefs);

                // Not all parameters have tokens. Parameters may have no token 
                // if they have no name and no attributes.
                ASSERT.CONSISTENCY_CHECK(cParamDefs <= sigArgCount + 1 /* return type */);
              

                for(uint i = 0; i < cParamDefs; i ++)
                {
                    #region Populate ParameterInfos
                    ParameterAttributes attr;
                    int position, tkParamDef = tkParamDefs[i];

                    scope.GetParamDefProps(tkParamDef, out position, out attr);

                    position --;

                    if (fetchReturnParameter == true && position == -1)
                    {
                        ASSERT.CONSISTENCY_CHECK(returnParameter == null);
                        returnParameter = new ParameterInfo(sig, scope, tkParamDef, position, attr, member);
                    }
                    else if (fetchReturnParameter == false && position >= 0)
                    {
                        ASSERT.CONSISTENCY_CHECK(position < sigArgCount);
                        args[position] = new ParameterInfo(sig, scope, tkParamDef, position, attr, member);
                    }
                    #endregion
                }
            }

            // Fill in empty ParameterInfos for those without tokens
            if (fetchReturnParameter)
            {
                if (returnParameter == null) 
                {
                    returnParameter = new ParameterInfo(sig, MetadataImport.EmptyImport, 0, -1,(ParameterAttributes)0, member);
                }
            }
            else
            {
                if (cParamDefs < args.Length + 1)
                {
                    for(int i = 0; i < args.Length; i ++)
                    {
                        if (args[i] != null)
                            continue;

                        args[i] = new ParameterInfo(sig, MetadataImport.EmptyImport, 0, i,(ParameterAttributes)0, member);
                    }
                }
            }

            return args;
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:73,代码来源:xxxinfos.cs


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