Skip to content

Commit

Permalink
Support generics and overloads for XML comments (#2982)
Browse files Browse the repository at this point in the history
* Document arrays of GenericParameters with XmlComments

* Overload methods with the same number of parameters
  • Loading branch information
jgarciadelanoceda authored Jul 17, 2024
1 parent f85abd4 commit fdb7d6b
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 12 deletions.
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 =>
{
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

0 comments on commit fdb7d6b

Please sign in to comment.