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

GetXmlDocsSummary is not working as expexted for generic base classes #127

Open
xC0dex opened this issue Apr 28, 2023 · 1 comment
Open

Comments

@xC0dex
Copy link

xC0dex commented Apr 28, 2023

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:
@xC0dex
Copy link
Author

xC0dex commented Jul 24, 2023

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant