Beispiel #1
0
        /// <summary>
        /// Adds the underlying nodes.
        /// </summary>
        /// <param name="type">The type to add.</param>
        /// <param name="definition">The object.</param>
        private void AddInnerDefinition(Type type, object?definition)
        {
            this.Nodes.Clear();

            if (definition != null)
            {
                foreach (var element in DefinitionParser.ParseToNodes(type, definition))
                {
                    this.AddNode(element);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a new node.
        /// </summary>
        /// <param name="i">The index.</param>
        /// <returns>The return value.</returns>
        private PropertyNode?CreateNode(int i)
        {
            ElementInfo kvpInfo = new ElementInfo(
                name: $"[{i}]",
                description: this.Description,
                propertyType: this.objectType,
                nullable: true,
                getValue: prop => this.HandleGetValue(i),
                setValue: (prop, value) => this.HandleSetValue(i, value),
                getCompiledParameters: this.info.GetCompiledParameters,
                compiled: this.info.Compiled,
                hiddenInEditorCondition: null);

            return(DefinitionParser.ToNode(this.underlyingObject, kvpInfo));
        }
        /// <summary>
        /// Creates a new node.
        /// </summary>
        /// <param name="key">The node key.</param>
        /// <returns>The node.</returns>
        private PropertyNode?CreateNode(object key)
        {
            ElementInfo kvpInfo = new ElementInfo(
                name: key as string ?? "UNKNOWN",
                description: this.info.Description,
                propertyType: this.valueType,
                nullable: true, // Set nullable to true, if the value is set to null than the element will be deleted.
                getValue: prop => this.AsDictionary()[prop.Name],
                setValue: (prop, value) => this.HandleSetValue(prop.Name, value),
                getCompiledParameters: this.info.GetCompiledParameters,
                compiled: this.info.Compiled,
                hiddenInEditorCondition: null)
            {
                ChangeName = (prop, newName) => this.ChangeName(prop.Name, newName),
                NameCreatesVariableName = true, // This is currently always true, should plumb in correctly with attribute for auto-magic.
            };

            return(DefinitionParser.ToNode(this.thing, kvpInfo));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyNode"/> class.
        /// </summary>
        /// <param name="thing">The thing this node points to.</param>
        /// <param name="property">The property info.</param>
        /// <param name="options">The options for this node.</param>
        /// <param name="readOnly">If this instance should be read only.</param>
        public PropertyNode(
            object?thing,
            ElementInfo property,
            IEnumerable <PropertyInfo> options,
            bool readOnly = false)
        {
            this.name               = property.Name;
            this.Description        = property.Description;
            this.Nullable           = property.Nullable;
            this.ContentsModifiable = !readOnly;

            this.changeName = property.ChangeName;

            this.GetContentsFunc         = property.GetValue;
            this.NameCreatesVariableName = property.NameCreatesVariableName;
            this.ControlsDefinitionName  = property.ControlsDefinitionName;
            this.ContentsType            = property.PropertyType;
            this.hiddenInEditor          = property.HiddenInEditor;

            if (!readOnly)
            {
                this.SetContentsFunc = property.SetValue;
            }

            foreach (PropertyInfo option in options)
            {
                PropertyNode?node = DefinitionParser.ToNode(thing, option);
                if (node != null)
                {
                    this.AddOption(node);
                }
            }

            // Set up that changes to Content or underlying nodes causes validation changes.
            this.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName?.Equals(nameof(this.Content)) ?? false)
                {
                    this.OnPropertyChanged(nameof(this.ValidationFailures));
                }
            };

            foreach (PropertyNode node in this.Nodes)
            {
                node.PropertyChanged += (s, e) =>
                {
                    if (e.PropertyName?.Equals(nameof(node.ValidationFailures)) ?? false)
                    {
                        this.OnPropertyChanged(nameof(this.ValidationFailures));
                    }
                };
            }

            foreach (PropertyNode node in this.Options)
            {
                node.PropertyChanged += (s, e) =>
                {
                    if (e.PropertyName?.Equals(nameof(node.ValidationFailures)) ?? false)
                    {
                        this.OnPropertyChanged(nameof(this.ValidationFailures));
                    }
                };
            }

            this.Nodes.CollectionChanged += this.NodeListItemsChanged;

            this.Options.CollectionChanged += this.NodeListItemsChanged;
        }