private static TypeReference ResolveIfNeeded(IGenericInstance genericInstanceMethod, IGenericInstance declaringGenericInstanceType, TypeReference parameterType)
{
var byRefType = parameterType as ByReferenceType;
if (byRefType != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, byRefType);
var arrayType = parameterType as ArrayType;
if (arrayType != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, arrayType);
var genericInstanceType = parameterType as GenericInstanceType;
if (genericInstanceType != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, genericInstanceType);
var genericParameter = parameterType as GenericParameter;
if (genericParameter != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, genericParameter);
var requiredModifierType = parameterType as RequiredModifierType;
if (requiredModifierType != null && ContainsGenericParameters (requiredModifierType))
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, requiredModifierType.ElementType);
if (ContainsGenericParameters (parameterType))
throw new Exception ("Unexpected generic parameter.");
return parameterType;
}