Namotion.Reflection
Namotion.Reflection copied to clipboard
GetXmlDocsSummary is not working as expexted for generic base classes
The GetXmlDocsSummary
method currently does not return a value for properties inherited from a generic class.
A simple example:
var type = Assembly.GetExecutingAssembly().GetTypes().First(x => x.Name.StartsWith("Child"));
foreach (var propertyInfo in type.GetProperties())
{
Console.WriteLine($"{propertyInfo.Name}: {propertyInfo.GetXmlDocsSummary()}");
}
public class GenericParent<T>
{
/// <summary>
/// This summary will be ignored.
/// </summary>
public T? Value { get; set; }
/// <summary>
/// This summary will also be ignored.
/// </summary>
public string? AnotherValue { get; set; }
}
public class Child<T>: GenericParent<T>
{
/// <summary>
/// This summary will be shown.
/// </summary>
public string? Name { get; set; }
}
Output:
Name: This summary will be shown.
Value:
AnotherValue:
I forked the project and debugged the GetXmlDocsSummary
and noticed that the following line throws an exception because the property FullName
of the DeclaringType is null:
https://github.com/RicoSuter/Namotion.Reflection/blob/33e53f600197357307599c7536daa7715e1dbd00/src/Namotion.Reflection/XmlDocsExtensions.cs#L634
According to the Microsoft docs this is correct because the type of generic type is unknown (which is the case in my example above).
The return of this line should be Namotion.Reflection.Tests.FullAssembly.GenericParent`1.Value
. However, this can also be achieved by writing the following:
memberName = member.DeclaringType.Namespace + "." + member.DeclaringType.Name + "." + member.Name;
Maybe there is a chance to check, if DeclaringType.FullName
is null and use the line above as a fallback? I could create a PR for this.
What do you think @RicoSuter ?