Fix .NET generic class typename to match old mono style without inlined assembly name and ver
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
46
Source/Engine/Utilities/TypeUtils.cs
Normal file
46
Source/Engine/Utilities/TypeUtils.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user