public static void PopulateBindNodes(Node Instance) { List <MemberInfo> Members = MDStatics.GetTypeMemberInfos(Instance); foreach (MemberInfo Member in Members) { MDBindNode BindAttr = Member.GetCustomAttribute(typeof(MDBindNode)) as MDBindNode; if (BindAttr == null) { continue; } Type MemberType = null; FieldInfo Field = Member as FieldInfo; PropertyInfo Property = Member as PropertyInfo; if (Field != null) { MemberType = Field.FieldType; } else if (Property != null) { MemberType = Property.PropertyType; } if (!MDStatics.IsSameOrSubclass(MemberType, typeof(Node))) { MDLog.Error(LOG_CAT, $"Not Node-Type field [{Member.Name}] on Node {Instance.Name} with Type [{Instance.GetType().Name}] was marked with [MDBindNode()]"); continue; } string PathToNode = BindAttr.GetNodePath(Member.Name); Node BoundNode = FindNode(Instance, PathToNode); if (BoundNode == null) { continue; } if (Field != null) { Field.SetValue(Instance, BoundNode); } else if (Property != null) { Property.SetValue(Instance, BoundNode); } } }
/// <summary>Helper to populate members marked with [MDBindNode()]</summary> public static void PopulateBindNodes(this Node Instance) { MDBindNode.PopulateBindNodes(Instance); }