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