PWAnchorField CreateAnchorField() { PWAnchorField newAnchorField = new PWAnchorField(); newAnchorField.Initialize(this); newAnchorField.OnEnable(); return(newAnchorField); }
void LoadFieldAttributes() { //get input variables System.Reflection.FieldInfo[] fInfos = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); List <string> actualFields = new List <string>(); foreach (var field in fInfos) { // reading field informations. actualFields.Add(field.Name); anchorFieldInfoMap[field.Name] = field; if (!anchorFieldDictionary.ContainsKey(field.Name)) { anchorFieldDictionary[field.Name] = CreateAnchorField(); } PWAnchorField anchorField = anchorFieldDictionary[field.Name]; //detect multi-anchor by checking for PWArray<T> type if (field.FieldType.IsGenericType) { if (field.FieldType.GetGenericTypeDefinition() == typeof(PWArray <>)) { anchorField.multiple = true; } } System.Object[] attrs = field.GetCustomAttributes(true); foreach (var attr in attrs) { PWInputAttribute inputAttr = attr as PWInputAttribute; PWOutputAttribute outputAttr = attr as PWOutputAttribute; PWColorAttribute colorAttr = attr as PWColorAttribute; PWOffsetAttribute offsetAttr = attr as PWOffsetAttribute; PWNotRequiredAttribute notRequiredAttr = attr as PWNotRequiredAttribute; if (inputAttr != null) { anchorField.anchorType = PWAnchorType.Input; if (inputAttr.name != null) { anchorField.name = inputAttr.name; } } if (outputAttr != null) { anchorField.anchorType = PWAnchorType.Output; if (outputAttr.name != null) { anchorField.name = outputAttr.name; } } if (colorAttr != null) { anchorField.color = new SerializableColor(colorAttr.color); } if (offsetAttr != null) { anchorField.offset = offsetAttr.offset; anchorField.padding = offsetAttr.padding; } if (notRequiredAttr != null) { anchorField.required = false; } } if (anchorField.anchorType == PWAnchorType.None) //field does not have a PW attribute { anchorFieldDictionary.Remove(field.Name); } else { //create anchor in this anchorField if there is not existing one if (anchorField.anchors.Count == 0) { anchorField.CreateNewAnchor(); } anchorField.colorSchemeName = PWColorTheme.GetAnchorColorSchemeName(field.FieldType); anchorField.fieldName = field.Name; anchorField.fieldType = (SerializableType)field.FieldType; anchorField.fieldValue = field.GetValue(this); anchorField.nodeRef = this; } } //remove inhexistants field dictionary entries (for renamed variables): var toRemoveKeys = new List <string>(); foreach (var kp in anchorFieldDictionary) { if (!actualFields.Contains(kp.Key)) { toRemoveKeys.Add(kp.Key); } } //remove duplicate keys in the dictionary (yes it happends ...) HashSet <string> duplicateKeys = new HashSet <string>(); foreach (var kp in anchorFieldDictionary) { // if (duplicateKeys.Contains(kp.Key)) // toRemoveKeys.Add(kp.Key); duplicateKeys.Add(kp.Key); } foreach (var toRemoveKey in toRemoveKeys) { anchorFieldDictionary.Remove(toRemoveKey); } }