mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Fixed #100 again
This commit is contained in:
parent
4c9264fed5
commit
8c731a9947
@ -35,7 +35,17 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool GetAttrib<T>(Type classType, string fieldName, out T attribOut) where T : Attribute {
|
public static bool GetAttrib<T>(Type classType, string fieldName, out T attribOut) where T : Attribute {
|
||||||
object[] attribs = classType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetCustomAttributes(typeof(T), false);
|
// If we can't find field in the first run, it's probably a private field in a base class.
|
||||||
|
FieldInfo field = classType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
// Search base classes for private fields only. Public fields are found above
|
||||||
|
while (field == null && (classType = classType.BaseType) != typeof(XNode.Node)) field = classType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
// This shouldn't happen. Ever.
|
||||||
|
if (field == null) {
|
||||||
|
Debug.LogWarning("Field " + fieldName + " couldnt be found");
|
||||||
|
attribOut = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
object[] attribs = field.GetCustomAttributes(typeof(T), false);
|
||||||
return GetAttrib(attribs, out attribOut);
|
return GetAttrib(attribs, out attribOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,12 +68,24 @@ namespace XNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<FieldInfo> GetNodeFields(System.Type nodeType) {
|
||||||
|
List<System.Reflection.FieldInfo> fieldInfo = new List<System.Reflection.FieldInfo>(nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
|
||||||
|
|
||||||
|
// GetFields doesnt return inherited private fields, so walk through base types and pick those up
|
||||||
|
System.Type tempType = nodeType;
|
||||||
|
while ((tempType = tempType.BaseType) != typeof(XNode.Node)) {
|
||||||
|
fieldInfo.AddRange(tempType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance));
|
||||||
|
}
|
||||||
|
return fieldInfo;
|
||||||
|
}
|
||||||
|
|
||||||
private static void CachePorts(System.Type nodeType) {
|
private static void CachePorts(System.Type nodeType) {
|
||||||
System.Reflection.FieldInfo[] fieldInfo = nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
List<System.Reflection.FieldInfo> fieldInfo = GetNodeFields(nodeType);
|
||||||
for (int i = 0; i < fieldInfo.Length; i++) {
|
|
||||||
|
for (int i = 0; i < fieldInfo.Count; i++) {
|
||||||
|
|
||||||
//Get InputAttribute and OutputAttribute
|
//Get InputAttribute and OutputAttribute
|
||||||
object[] attribs = fieldInfo[i].GetCustomAttributes(false);
|
object[] attribs = fieldInfo[i].GetCustomAttributes(true);
|
||||||
Node.InputAttribute inputAttrib = attribs.FirstOrDefault(x => x is Node.InputAttribute) as Node.InputAttribute;
|
Node.InputAttribute inputAttrib = attribs.FirstOrDefault(x => x is Node.InputAttribute) as Node.InputAttribute;
|
||||||
Node.OutputAttribute outputAttrib = attribs.FirstOrDefault(x => x is Node.OutputAttribute) as Node.OutputAttribute;
|
Node.OutputAttribute outputAttrib = attribs.FirstOrDefault(x => x is Node.OutputAttribute) as Node.OutputAttribute;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user