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

IXamlType.FullName Inconsistency #119

Open
workgroupengineering opened this issue Apr 30, 2024 · 7 comments
Open

IXamlType.FullName Inconsistency #119

workgroupengineering opened this issue Apr 30, 2024 · 7 comments

Comments

@workgroupengineering
Copy link
Contributor

workgroupengineering commented Apr 30, 2024

While devlop test for #112, i found inconsistency when i get FullName of GenericType.

Sre

TypeSystemTest.Models.GenericType`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]

Cecil

TypeSystemTest.Models.GenericType`1<System.String>

Which of both is the expected behavior?

@maxkatz6
Copy link
Collaborator

Likely, Cecil one is expected.

Sre is a mix of Type.AssemblyQualifiedName (for generics) and FullName for the main type name itself.

Also, anything that compatible with .NET TypeNameParser is a bonus:
dotnet/runtime#97566

@maxkatz6
Copy link
Collaborator

Looks like it's an expected behavior for Type.FullName to return assembly qualified names for generics. For some reason.
https://learn.microsoft.com/en-us/dotnet/api/system.type.assemblyqualifiedname?view=net-8.0

@maxkatz6
Copy link
Collaborator

For your tests, you might want to use these extensions probably:

public static string GetFqn(this IXamlType type) => $"{type.Assembly?.Name}:{type.Namespace}.{type.Name}";
public static string GetFullName(this IXamlType type)
{
var name = type.Name;
if (type.Namespace != null)
name = type.Namespace + "." + name;
if (type.Assembly != null)
name += "," + type.Assembly.Name;
return name;
}

Unless our GetFullName extension is missing generics (which it might do).

@workgroupengineering
Copy link
Contributor Author

What do you think if I normalized the Sre FullName like in Cecil instead of using an extension method?

@maxkatz6
Copy link
Collaborator

I don't know if it will break anything. It would require double checking any FullName usage.
Also, it's still not clear which variant is more standard.

@kasperk81
Copy link

Also, it's still not clear which variant is more standard.

there is no spec: dotnet/runtime#97566 (comment)

in the future, more systems are likely to depend on TypeNameParser's behavior. @adamsitnik may able to clarify some confusion. cecil should probably switch to TNP for net9-and-above

@adamsitnik
Copy link

cecil should probably switch to TNP for net9-and-above

The new TypeName API is part of System.Reflection.Metadata package, which supports older monikers too:

image

Looks like it's an expected behavior for Type.FullName to return assembly qualified names for generics

Yes, but only for the generic arguments.

> typeof(List<int>).FullName
"System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
> typeof(List<int>).AssemblyQualifiedName
"System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"

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

4 participants