Exemplo n.º 1
0
        void LoadFieldAttributes()
        {
            //get input variables
            System.Reflection.FieldInfo[] fInfos = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            List <string> actualFields = new List <string>();

            anchorFieldInfoMap.Clear();

            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();
                }

                AnchorField 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)
                {
                    InputAttribute       inputAttr       = attr as InputAttribute;
                    OutputAttribute      outputAttr      = attr as OutputAttribute;
                    ColorAttribute       colorAttr       = attr as ColorAttribute;
                    OffsetAttribute      offsetAttr      = attr as OffsetAttribute;
                    VisibilityAttribute  visibilityAttr  = attr as VisibilityAttribute;
                    NotRequiredAttribute notRequiredAttr = attr as NotRequiredAttribute;

                    if (inputAttr != null)
                    {
                        anchorField.anchorType = AnchorType.Input;
                        if (inputAttr.name != null)
                        {
                            anchorField.name = inputAttr.name;
                        }
                    }
                    if (outputAttr != null)
                    {
                        anchorField.anchorType = AnchorType.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 (visibilityAttr != null)
                    {
                        anchorField.defaultVisibility = visibilityAttr.visibility;
                    }
                }
                if (anchorField.anchorType == AnchorType.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 = ColorTheme.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);
                }
            }

            foreach (var toRemoveKey in toRemoveKeys)
            {
                anchorFieldDictionary.Remove(toRemoveKey);
            }
        }