Merge pull request #56 from theo-rapidfire/fix/use-type-cache
Performance improvement: Use TypeCache instead of manual type iteration
This commit is contained in:
commit
2b40c3d26e
@ -26,49 +26,47 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
|||||||
static Type GetCustomPropertyDrawerType (Type type)
|
static Type GetCustomPropertyDrawerType (Type type)
|
||||||
{
|
{
|
||||||
Type[] interfaceTypes = type.GetInterfaces();
|
Type[] interfaceTypes = type.GetInterfaces();
|
||||||
|
|
||||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
var types = TypeCache.GetTypesWithAttribute<CustomPropertyDrawer>();
|
||||||
|
foreach (Type drawerType in types)
|
||||||
{
|
{
|
||||||
foreach (Type drawerType in assembly.GetTypes())
|
var customPropertyDrawerAttributes = drawerType.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
|
||||||
|
foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes)
|
||||||
{
|
{
|
||||||
var customPropertyDrawerAttributes = drawerType.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
|
var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes)
|
if (field != null)
|
||||||
{
|
{
|
||||||
var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance);
|
var fieldType = field.GetValue(customPropertyDrawer) as Type;
|
||||||
if (field != null)
|
if (fieldType != null)
|
||||||
{
|
{
|
||||||
var fieldType = field.GetValue(customPropertyDrawer) as Type;
|
if (fieldType == type)
|
||||||
if (fieldType != null)
|
|
||||||
{
|
{
|
||||||
if (fieldType == type)
|
return drawerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the property drawer also allows for being applied to child classes, check if they match
|
||||||
|
var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
if (useForChildrenField != null)
|
||||||
|
{
|
||||||
|
object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer);
|
||||||
|
if (useForChildrenValue is bool && (bool)useForChildrenValue)
|
||||||
{
|
{
|
||||||
return drawerType;
|
// Check interfaces
|
||||||
}
|
if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType))
|
||||||
|
|
||||||
// If the property drawer also allows for being applied to child classes, check if they match
|
|
||||||
var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
if (useForChildrenField != null)
|
|
||||||
{
|
|
||||||
object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer);
|
|
||||||
if (useForChildrenValue is bool && (bool)useForChildrenValue)
|
|
||||||
{
|
{
|
||||||
// Check interfaces
|
return drawerType;
|
||||||
if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType))
|
}
|
||||||
|
|
||||||
|
// Check derived types
|
||||||
|
Type baseType = type.BaseType;
|
||||||
|
while (baseType != null)
|
||||||
|
{
|
||||||
|
if (baseType == fieldType)
|
||||||
{
|
{
|
||||||
return drawerType;
|
return drawerType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check derived types
|
baseType = baseType.BaseType;
|
||||||
Type baseType = type.BaseType;
|
|
||||||
while (baseType != null)
|
|
||||||
{
|
|
||||||
if (baseType == fieldType)
|
|
||||||
{
|
|
||||||
return drawerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
baseType = baseType.BaseType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user