1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 01:36:03 +08:00

Merge pull request #237 from jeffcampbellmakesgames/fix/cache_adds_duplicate_fields

Added fix for duplicate node fields found
This commit is contained in:
Thor Brigsted 2020-03-08 14:46:23 +01:00 committed by GitHub
commit 172bdbb7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,7 +156,14 @@ namespace XNode {
// GetFields doesnt return inherited private fields, so walk through base types and pick those up // GetFields doesnt return inherited private fields, so walk through base types and pick those up
System.Type tempType = nodeType; System.Type tempType = nodeType;
while ((tempType = tempType.BaseType) != typeof(XNode.Node)) { while ((tempType = tempType.BaseType) != typeof(XNode.Node)) {
fieldInfo.AddRange(tempType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)); FieldInfo[] parentFields = tempType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
for (int i = 0; i < parentFields.Length; i++) {
// Ensure that we do not already have a member with this type and name
FieldInfo parentField = parentFields[i];
if (fieldInfo.TrueForAll(x => x.Name != parentField.Name)) {
fieldInfo.Add(parentField);
}
}
} }
return fieldInfo; return fieldInfo;
} }