Fix .NET generic class typename to match old mono style without inlined assembly name and ver

This commit is contained in:
Wojtek Figat
2023-03-27 17:30:48 +02:00
parent 510fc443e8
commit 4755c42d70
62 changed files with 133 additions and 65 deletions

View File

@@ -1988,17 +1988,11 @@ namespace FlaxEngine
{
var type = assemblyTypes[i];
IntPtr ptr = IntPtr.Add(new IntPtr(arr), Unsafe.SizeOf<NativeClassDefinitions>() * i);
bool isStatic = type.IsAbstract && type.IsSealed;
bool isInterface = type.IsInterface;
bool isAbstract = type.IsAbstract;
ManagedHandle typeHandle = GetTypeGCHandle(type);
NativeClassDefinitions managedClass = new NativeClassDefinitions()
var managedClass = new NativeClassDefinitions
{
typeHandle = typeHandle,
typeHandle = GetTypeGCHandle(type),
name = NativeAllocStringAnsi(type.Name),
fullname = NativeAllocStringAnsi(type.FullName),
fullname = NativeAllocStringAnsi(type.GetTypeName()),
@namespace = NativeAllocStringAnsi(type.Namespace ?? ""),
typeAttributes = (uint)type.Attributes,
};
@@ -2013,12 +2007,11 @@ namespace FlaxEngine
internal static unsafe void GetManagedClassFromType(ManagedHandle typeHandle, NativeClassDefinitions* managedClass, ManagedHandle* assemblyHandle)
{
Type type = Unsafe.As<Type>(typeHandle.Target);
ManagedHandle classTypeHandle = GetTypeGCHandle(type);
*managedClass = new NativeClassDefinitions()
*managedClass = new NativeClassDefinitions
{
typeHandle = classTypeHandle,
typeHandle = GetTypeGCHandle(type),
name = NativeAllocStringAnsi(type.Name),
fullname = NativeAllocStringAnsi(type.FullName),
fullname = NativeAllocStringAnsi(type.GetTypeName()),
@namespace = NativeAllocStringAnsi(type.Namespace ?? ""),
typeAttributes = (uint)type.Attributes,
};

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Text;
namespace FlaxEngine.Utilities
{
/// <summary>
/// Editor utilities and helper functions for System.Type.
/// </summary>
public static partial class TypeUtils
{
/// <summary>
/// Gets the typename full name.
/// </summary>
/// <param name="type">The type.</param>
/// <returns>The full typename of the type.</returns>
public static string GetTypeName(this Type type)
{
if (type.IsGenericType && type.IsConstructedGenericType)
{
// For generic types (eg. Dictionary) FullName returns generic parameter types with fully qualified name so simplify it manually
var sb = new StringBuilder();
sb.Append(type.Namespace);
sb.Append('.');
sb.Append(type.Name);
sb.Append('[');
var genericArgs = type.GetGenericArguments();
for (var i = 0; i < genericArgs.Length; i++)
{
if (i != 0)
sb.Append(',');
sb.Append(genericArgs[i].GetTypeName());
}
sb.Append(']');
var sss = sb.ToString();
if (sss != type.FullName)
{
Debug.LogError($"Different type name: {type.FullName} vs {sss}");
}
return sb.ToString();
}
return type.FullName;
}
}
}