Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document arrays of GenericParameters with XmlComments and support Overload methods #2982

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,69 @@ public static MethodInfo GetUnderlyingGenericTypeMethod(this MethodInfo construc
{
var constructedType = constructedTypeMethod.DeclaringType;
var genericTypeDefinition = constructedType.GetGenericTypeDefinition();
var genericArguments = constructedType.GenericTypeArguments;

var constructedTypeParameters = constructedTypeMethod.GetParameters();

// Retrieve list of candidate methods that match name and parameter count
var candidateMethods = genericTypeDefinition.GetMethods()
.Where(m =>
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
{
return (m.Name == constructedTypeMethod.Name)
&& (m.GetParameters().Length == constructedTypeMethod.GetParameters().Length);
var genericTypeDefinitionParameters = m.GetParameters();
if (m.Name == constructedTypeMethod.Name && genericTypeDefinitionParameters.Length == constructedTypeParameters.Length)
{
for (var i = 0; i < genericTypeDefinitionParameters.Length; i++)
{
if (genericTypeDefinitionParameters[i].ParameterType.IsArray && constructedTypeParameters[i].ParameterType.IsArray)
{
var genericTypeDefinitionElement = genericTypeDefinitionParameters[i].ParameterType.GetElementType();
var constructedTypeDefinitionElement = constructedTypeParameters[i].ParameterType.GetElementType();
if (genericTypeDefinitionElement.IsGenericParameter && genericArguments.Any(p => p == constructedTypeDefinitionElement))
{
continue;
}
else if (genericTypeDefinitionElement != constructedTypeDefinitionElement)
{
return false;
}
}
else if (genericTypeDefinitionParameters[i].ParameterType.IsConstructedGenericType && constructedTypeParameters[i].ParameterType.IsConstructedGenericType)
{
if (genericTypeDefinitionParameters[i].ParameterType.GetGenericTypeDefinition() != constructedTypeParameters[i].ParameterType.GetGenericTypeDefinition())
{
return false;
}
var genericTypeDefinitionArguments = genericTypeDefinitionParameters[i].ParameterType.GetGenericArguments();
var constructedDefinitionArguments = constructedTypeParameters[i].ParameterType.GetGenericArguments();
if (genericTypeDefinitionArguments.Length != constructedDefinitionArguments.Length)
{
return false;
}
for (var j = 0; j < genericTypeDefinitionArguments.Length; j++)
{
if (genericTypeDefinitionArguments[j].IsGenericParameter && genericArguments.Any(p => p == constructedDefinitionArguments[j]))
{
continue;
}
else if (genericTypeDefinitionArguments[j] != constructedDefinitionArguments[j])
{
return false;
}
}
continue;
}
else if (genericTypeDefinitionParameters[i].ParameterType.IsGenericParameter && genericArguments.Any(p => p == constructedTypeParameters[i].ParameterType))
{
continue;
}
else if (genericTypeDefinitionParameters[i].ParameterType != constructedTypeParameters[i].ParameterType)
{
return false;
}
}
return true;
}
return false;
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public static string GetMemberNameForFieldOrProperty(MemberInfo fieldOrPropertyI
private static string QualifiedNameFor(Type type, bool expandGenericArgs = false)
{
if (type.IsArray)
return $"{QualifiedNameFor(type.GetElementType(), expandGenericArgs)}[]";
{
var elementType = type.GetElementType();
return elementType.IsGenericParameter ? $"`{elementType.GenericParameterPosition}[]" : $"{QualifiedNameFor(type.GetElementType(), expandGenericArgs)}[]";
}


var builder = new StringBuilder();

Expand Down
Loading