Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Include cmods in ModuleBuilder.GetMemberRefToken
Browse files Browse the repository at this point in the history
This method reproduces a method's signature for use in a MethodRef
metadata entry, but currently ignores custom modifiers placed in the
method's parameters.

This commit adds a new method overload (in order to avoid a larger
refactoring for now) that allows the inclusion of custom modifiers.
  • Loading branch information
stakx committed May 4, 2018
1 parent d142ffd commit ee6e784
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/mscorlib/src/System/Reflection/Emit/ModuleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private static RuntimeModule GetRuntimeModuleFromModule(Module m)

private int GetMemberRefToken(MethodBase method, IEnumerable<Type> optionalParameterTypes)
{
Type[] parameterTypes;
ParameterInfo[] parameterInfos;
Type returnType;
int tkParent;
int cGenericParameters = 0;
Expand Down Expand Up @@ -447,17 +447,29 @@ private int GetMemberRefToken(MethodBase method, IEnumerable<Type> optionalParam
}
}

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

Type[] parameterTypes = new Type[parameterInfos.Length];
Type[][] parameterRequiredCustomModifiers = new Type[parameterTypes.Length][];
Type[][] parameterOptionalCustomModifiers = new Type[parameterTypes.Length][];

for (int i = 0; i < parameterTypes.Length; i++)
{
parameterTypes[i] = parameterInfos[i].ParameterType;
parameterRequiredCustomModifiers[i] = parameterInfos[i].GetRequiredCustomModifiers();
parameterOptionalCustomModifiers[i] = parameterInfos[i].GetOptionalCustomModifiers();
}

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

if (method.DeclaringType.IsGenericType)
Expand Down Expand Up @@ -485,14 +497,28 @@ private int GetMemberRefToken(MethodBase method, IEnumerable<Type> optionalParam

internal SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType,
Type[] parameterTypes, IEnumerable<Type> optionalParameterTypes, int cGenericParameters)
{
return GetMemberRefSignature(call, returnType, parameterTypes, null, null, optionalParameterTypes, cGenericParameters);
}

internal SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType,
Type[] parameterTypes, Type[][] parameterRequiredCustomModifiers, Type[][] parameterOptionalCustomModifiers,
IEnumerable<Type> optionalParameterTypes, int cGenericParameters)
{
SignatureHelper sig = SignatureHelper.GetMethodSigHelper(this, call, returnType, cGenericParameters);

Debug.Assert(parameterRequiredCustomModifiers == null || (parameterTypes != null && parameterRequiredCustomModifiers.Length == parameterTypes.Length));
Debug.Assert(parameterOptionalCustomModifiers == null || (parameterTypes != null && parameterOptionalCustomModifiers.Length == parameterTypes.Length));

if (parameterTypes != null)
{
int i = 0;
foreach (Type t in parameterTypes)
{
sig.AddArgument(t);
Type[] requiredCustomModifiers = parameterRequiredCustomModifiers != null ? parameterRequiredCustomModifiers[i] : null;
Type[] optionalCustomModifiers = parameterOptionalCustomModifiers != null ? parameterOptionalCustomModifiers[i] : null;
sig.AddArgument(t, requiredCustomModifiers, optionalCustomModifiers);
i++;
}
}

Expand Down

0 comments on commit ee6e784

Please sign in to comment.