@@ -19,19 +19,37 @@ public Report Validate()
1919 for ( int i = 0 ; i < objects . Count ; i ++ )
2020 {
2121 EditorUtility . DisplayProgressBar ( "RequiredAttributeAssetValidator" , "RequiredAttribute..." , ( float ) i / objects . Count ) ;
22- IEnumerable < ( FieldInfo FieldInfo , RequiredAttribute Attribute ) > fieldsWithRequiredAttribute = from fi in objects [ i ] . GetType ( ) . GetFields ( )
23- let attr = fi . GetCustomAttributes ( typeof ( RequiredAttribute ) , true )
24- where attr . Length == 1
25- select ( FieldInfo : fi , Attribute : attr . First ( ) as RequiredAttribute ) ;
2622
27- foreach ( ( FieldInfo FieldInfo , RequiredAttribute Attribute ) field in fieldsWithRequiredAttribute )
23+ FieldInfo [ ] fields = objects [ i ] . GetType ( ) . GetFields ( ) ;
24+
25+ for ( int j = 0 ; j < fields . Length ; j ++ )
2826 {
29- object o = field . FieldInfo . GetValue ( objects [ i ] ) ;
30- if ( o == null || o . Equals ( null ) )
27+ object [ ] attr = fields [ j ] . GetCustomAttributes ( typeof ( RequiredAttribute ) , true ) ;
28+
29+ if ( attr . Length > 0 && attr [ 0 ] is RequiredAttribute requiredAttribute )
3130 {
32- report . Log ( objects [ i ] , field . Attribute . WarningType , field . Attribute . Category , $ "{ field . FieldInfo . Name } is null", $ "Assign { field . FieldInfo . FieldType } ") ;
31+ object o = fields [ j ] . GetValue ( objects [ i ] ) ;
32+
33+ if ( o == null || o . Equals ( null ) )
34+ {
35+ report . Log ( objects [ i ] , requiredAttribute . WarningType , requiredAttribute . Category , $ "{ fields [ j ] . Name } is null", $ "Assign { fields [ j ] . FieldType } ") ;
36+ }
3337 }
3438 }
39+
40+ //IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields()
41+ // let attr = fi.GetCustomAttributes(typeof(RequiredAttribute), true)
42+ // where attr.Length == 1
43+ // select (FieldInfo: fi, Attribute: attr.First() as RequiredAttribute);
44+
45+ //foreach ((FieldInfo FieldInfo, RequiredAttribute Attribute) field in fieldsWithRequiredAttribute)
46+ //{
47+ // object o = field.FieldInfo.GetValue(objects[i]);
48+ // if (o == null || o.Equals(null))
49+ // {
50+ // report.Log(objects[i], field.Attribute.WarningType, field.Attribute.Category, $"{field.FieldInfo.Name} is null", $"Assign {field.FieldInfo.FieldType}");
51+ // }
52+ //}
3553 }
3654 EditorUtility . ClearProgressBar ( ) ;
3755
0 commit comments