Skip to content

Commit

Permalink
Fix issue where RuntimeClassName for boxed type object was empty stri…
Browse files Browse the repository at this point in the history
…ng (#1548)

* Handle get runtime classname on System.Type

* Add test
  • Loading branch information
manodasanW authored Mar 22, 2024
1 parent a4ccb0a commit 435ad48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,9 @@ public void TestGetRuntimeClassName()
Assert.Equal("Windows.Foundation.IReference`1<Int32>", Class.GetName(arr3.GetValue(0)));
Assert.Equal(string.Empty, Class.GetName(arr4[0]));
Assert.Equal("Windows.Foundation.IReference`1<Windows.Foundation.PropertyType>", Class.GetName(arr5.GetValue(0)));

Assert.Equal("Windows.Foundation.IReference`1<Windows.UI.Xaml.Interop.TypeName>", Class.GetName(typeof(IProperties1)));
Assert.Equal("Windows.Foundation.IReference`1<Windows.UI.Xaml.Interop.TypeName>", Class.GetName(typeof(Type)));
}

[Fact]
Expand Down Expand Up @@ -2312,6 +2315,13 @@ public void TypeInfoGenerics()
Assert.Equal("Windows.Foundation.Collections.IVector`1<Int32>", typeName);
}

[Fact]
public void TypeInfoType()
{
var typeName = Class.GetTypeNameForType(typeof(Type));
Assert.Equal("Windows.UI.Xaml.Interop.TypeName", typeName);
}

[Fact]
public void TestGenericTypeMarshalling()
{
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static (String Name, TypeKind Kind) ToAbi(global::System.Type value)
{
kind = TypeKind.Primitive;
}
else if (value == typeof(object) || value == typeof(string) || value == typeof(Guid) || value == typeof(System.Type))
else if (value == typeof(object) || value == typeof(string) || value == typeof(Guid) || value == typeof(global::System.Type))
{
kind = TypeKind.Metadata;
}
Expand Down
6 changes: 5 additions & 1 deletion src/WinRT.Runtime/TypeNameSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,15 @@ private static bool TryAppendSimpleTypeName(Type type, StringBuilder builder, Ty
else if (type == typeof(object))
{
builder.Append("Object");
}
else if ((flags & TypeNameGenerationFlags.ForGetRuntimeClassName) != 0 && type.IsTypeOfType())
{
builder.Append("Windows.UI.Xaml.Interop.TypeName");
}
else
{
var projectedAbiTypeName = Projections.FindCustomAbiTypeNameForType(type);
if (projectedAbiTypeName is object)
if (projectedAbiTypeName is not null)
{
builder.Append(projectedAbiTypeName);
}
Expand Down

0 comments on commit 435ad48

Please sign in to comment.