RicoSuter / Namotion.Reflection

.NET library with advanced reflection APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GetXmlDocsSummary is not working as expexted for generic base classes

xC0dex opened this issue · comments

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:

type.FullName.FirstToken('[') : ((string)member.DeclaringType.FullName).FirstToken('[') + "." + member.Name;

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 ?