本文整理汇总了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;
}
示例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;
}