@@ -10,7 +10,8 @@ namespace Toolbox.Editor
1010{
1111 public static partial class PropertyUtility
1212 {
13- //TODO: temp
13+ //NOTE: last non-reflection implementation was ok but support for [SerializeReference] makes it a bit slow
14+ // unfortunately UnityEditor.ScriptAttributeUtility.GetFieldInfoFromProperty is internal so we have to retrive it using reflection
1415 private static readonly MethodInfo getGetFieldInfoFromPropertyMethod =
1516 ReflectionUtility . GetEditorMethod ( "UnityEditor.ScriptAttributeUtility" , "GetFieldInfoFromProperty" ,
1617 BindingFlags . NonPublic | BindingFlags . Static ) ;
@@ -254,7 +255,6 @@ public static Type GetScriptTypeFromProperty(SerializedProperty property)
254255 return scriptInstance . GetClass ( ) ;
255256 }
256257
257-
258258 public static FieldInfo GetFieldInfo ( this SerializedProperty property )
259259 {
260260 return GetFieldInfo ( property , out _ ) ;
@@ -266,16 +266,9 @@ public static FieldInfo GetFieldInfo(this SerializedProperty property, out Type
266266 var result = getGetFieldInfoFromPropertyMethod . Invoke ( null , parameters ) as FieldInfo ;
267267 propertyType = parameters [ 1 ] as Type ;
268268 return result ;
269-
270- //NOTE: ...
271- //return GetFieldInfoFromProperty(property, out propertyType);
272- }
273-
274- public static FieldInfo GetFieldInfo ( this SerializedProperty property , out Type propertyType , Object target )
275- {
276- return GetFieldInfoFromProperty ( property , out propertyType , target . GetType ( ) ) ;
277269 }
278270
271+ [ Obsolete ( "This method is no longer safe, use GetFieldInfo() instead." ) ]
279272 public static FieldInfo GetFieldInfoFromProperty ( SerializedProperty property , out Type type )
280273 {
281274 var classType = GetScriptTypeFromProperty ( property ) ;
@@ -288,8 +281,7 @@ public static FieldInfo GetFieldInfoFromProperty(SerializedProperty property, ou
288281 return GetFieldInfoFromProperty ( property , out type , classType ) ;
289282 }
290283
291- //NOTE: ...
292- //TODO: make it internal
284+ [ Obsolete ( "This method is no longer safe, use GetFieldInfo() instead." ) ]
293285 public static FieldInfo GetFieldInfoFromProperty ( SerializedProperty property , out Type type , Type host )
294286 {
295287 const BindingFlags fieldFlags = BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
@@ -397,7 +389,7 @@ public static SerializedProperty GetSize(this SerializedProperty array)
397389
398390 public static T GetAttribute < T > ( SerializedProperty property ) where T : Attribute
399391 {
400- return GetAttribute < T > ( property , GetFieldInfoFromProperty ( property , out _ ) ) ;
392+ return GetAttribute < T > ( property , GetFieldInfo ( property , out _ ) ) ;
401393 }
402394
403395 public static T GetAttribute < T > ( SerializedProperty property , FieldInfo fieldInfo ) where T : Attribute
@@ -407,7 +399,7 @@ public static T GetAttribute<T>(SerializedProperty property, FieldInfo fieldInfo
407399
408400 public static T [ ] GetAttributes < T > ( SerializedProperty property ) where T : Attribute
409401 {
410- return GetAttributes < T > ( property , GetFieldInfoFromProperty ( property , out _ ) ) ;
402+ return GetAttributes < T > ( property , GetFieldInfo ( property , out _ ) ) ;
411403 }
412404
413405 public static T [ ] GetAttributes < T > ( SerializedProperty property , FieldInfo fieldInfo ) where T : Attribute
0 commit comments