@@ -15,22 +15,30 @@ public static class ComponentExtensions
15
15
{ "mesh" , "sharedMesh" }
16
16
} ;
17
17
18
- public static T TransferValuesFrom < T > ( this Component comp , T other , bool ? considerBaseClasses = null ) where T : Component
18
+ public static T TransferValuesFrom < T > ( this Component comp , T other , bool considerBaseClasses = true ) where T : Component
19
19
{
20
- var conditionalFlags = ( considerBaseClasses ?? false ) ? BindingFlags . FlattenHierarchy : BindingFlags . DeclaredOnly ;
21
- Type type = comp . GetType ( ) ; //type of the copy
22
- if ( type != other . GetType ( ) ) return null ; // type mis-match
20
+ var conditionalFlags = considerBaseClasses ? BindingFlags . FlattenHierarchy : BindingFlags . DeclaredOnly ;
21
+
22
+ // Type of the copy
23
+ Type type = comp . GetType ( ) ;
24
+
25
+ // Type mismatch
26
+ if ( type != other . GetType ( ) )
27
+ {
28
+ return null ;
29
+ }
30
+
23
31
BindingFlags flags = BindingFlags . Public | BindingFlags . Instance | BindingFlags . Default | conditionalFlags ;
24
- PropertyInfo [ ] pinfos = type . GetProperties ( flags ) ;
32
+ PropertyInfo [ ] propertyInfos = type . GetProperties ( flags ) ;
25
33
26
34
//Handle variables
27
- foreach ( var pinfo in pinfos )
35
+ foreach ( var pinfo in propertyInfos )
28
36
{
29
37
if ( pinfo . CanWrite )
30
38
{
31
39
try
32
40
{
33
- //Ignore obsolete variables to avoid editor warnings
41
+ // Ignore obsolete variables to avoid editor warnings
34
42
if ( HasAnnotation < ObsoleteAttribute > ( pinfo ) || HasAnnotation < NotSupportedException > ( pinfo ) || HasAnnotation < System . ComponentModel . EditorBrowsableAttribute > ( pinfo ) )
35
43
{
36
44
continue ;
@@ -49,7 +57,7 @@ public static T TransferValuesFrom<T>(this Component comp, T other, bool? consid
49
57
}
50
58
}
51
59
52
- //Handle properties
60
+ // Handle properties
53
61
FieldInfo [ ] finfos = type . GetFields ( flags ) ;
54
62
55
63
foreach ( var finfo in finfos )
0 commit comments