mirror of
https://github.com/maxartz15/Validator.git
synced 2024-11-21 19:55:34 +01:00
Fix attribute
This commit is contained in:
parent
b13cf47fbf
commit
b4dd8744df
@ -1,4 +1,8 @@
|
||||
# Change Log:
|
||||
## 0.1.3
|
||||
- Fix attribute validator..?
|
||||
- ## 0.1.2
|
||||
- ...
|
||||
## 0.1.1
|
||||
- First prototype of Attribute validator.
|
||||
## 0.1.1
|
||||
|
@ -19,19 +19,37 @@ namespace Validator.Editor
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("RequiredAttributeAssetValidator", "RequiredAttribute...", (float)i / objects.Count);
|
||||
IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields()
|
||||
let attr = fi.GetCustomAttributes(typeof(RequiredAttribute), true)
|
||||
where attr.Length == 1
|
||||
select (FieldInfo: fi, Attribute: attr.First() as RequiredAttribute);
|
||||
|
||||
foreach ((FieldInfo FieldInfo, RequiredAttribute Attribute) field in fieldsWithRequiredAttribute)
|
||||
FieldInfo[] fields = objects[i].GetType().GetFields();
|
||||
|
||||
for (int j = 0; j < fields.Length; j++)
|
||||
{
|
||||
object o = field.FieldInfo.GetValue(objects[i]);
|
||||
if (o == null || o.Equals(null))
|
||||
object[] attr = fields[j].GetCustomAttributes(typeof(RequiredAttribute), true);
|
||||
|
||||
if(attr.Length > 0 && attr[0] is RequiredAttribute requiredAttribute)
|
||||
{
|
||||
report.Log(objects[i], field.Attribute.WarningType, field.Attribute.Category, $"{field.FieldInfo.Name} is null", $"Assign {field.FieldInfo.FieldType}");
|
||||
object o = fields[j].GetValue(objects[i]);
|
||||
|
||||
if (o == null || o.Equals(null))
|
||||
{
|
||||
report.Log(objects[i], requiredAttribute.WarningType, requiredAttribute.Category, $"{fields[j].Name} is null", $"Assign {fields[j].FieldType}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields()
|
||||
// let attr = fi.GetCustomAttributes(typeof(RequiredAttribute), true)
|
||||
// where attr.Length == 1
|
||||
// select (FieldInfo: fi, Attribute: attr.First() as RequiredAttribute);
|
||||
|
||||
//foreach ((FieldInfo FieldInfo, RequiredAttribute Attribute) field in fieldsWithRequiredAttribute)
|
||||
//{
|
||||
// object o = field.FieldInfo.GetValue(objects[i]);
|
||||
// if (o == null || o.Equals(null))
|
||||
// {
|
||||
// report.Log(objects[i], field.Attribute.WarningType, field.Attribute.Category, $"{field.FieldInfo.Name} is null", $"Assign {field.FieldInfo.FieldType}");
|
||||
// }
|
||||
//}
|
||||
}
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.vertexcolor.validator",
|
||||
"displayName": "Validator",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"unity": "2019.3",
|
||||
"description": "Unity project validator framework.",
|
||||
"category": "Tool",
|
||||
|
Loading…
Reference in New Issue
Block a user