Avoid pre-allocating custom attributes for managed types

This commit is contained in:
2022-12-11 13:54:12 +02:00
parent 84f8e3a4b4
commit b9f11298e8
4 changed files with 57 additions and 4 deletions

View File

@@ -1365,6 +1365,18 @@ namespace FlaxEngine
*classAttributesCount = attributeTypes.Length;
}
[UnmanagedCallersOnly]
internal static IntPtr GetCustomAttribute(IntPtr typeHandle, IntPtr attribHandle)
{
Type type = (Type)GCHandle.FromIntPtr(typeHandle).Target;
Type attribType = (Type)GCHandle.FromIntPtr(attribHandle).Target;
object attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x.GetType() == attribType);
if (attrib != null)
return GCHandle.ToIntPtr(GCHandle.Alloc(attrib, GCHandleType.Weak));
return IntPtr.Zero;
}
[UnmanagedCallersOnly]
internal static void GetClassInterfaces(IntPtr typeHandle, IntPtr* classInterfaces, int* classInterfacesCount)
{