Bender.Nodes.Object.EnumerableNode.AddNode C# (CSharp) Method

AddNode() protected method

protected AddNode ( INode node, bool named, Action modify ) : void
node INode
named bool
modify Action
return void
        protected override void AddNode(INode node, bool named, Action<INode> modify)
        {
            const string supported = "generic lists and generic enumerable interfaces";
            if (!SpecifiedType.IsGenericEnumerable) throw new TypeNotSupportedException(
                "non generic {0}".ToFormat(SpecifiedType.IsList ? "list" : "enumerable"),
                SpecifiedType, Mode.Deserialize, supported);

            if (_itemType.CanBeCastTo<INode>())
            {
                if (_itemType.Is<INode>() || _itemType.IsTypeOf(node)) _list.Value.Add(node);
            }
            else
            {
                if (Context.Options.TypeFilter.WhenNot(_itemType, Context.Options)) return;
                if (!ActualType.IsList) throw new TypeNotSupportedException(
                    "enumerable", ActualType, Mode.Deserialize, supported);
                if (named)
                {
                    var itemName = GetItemName(_itemType);
                    if (!node.Name.Equals(itemName, Context.Options.Deserialization.NameComparison))
                    {
                        if (Context.Options.Deserialization.IgnoreUnmatchedArrayItems) return;
                        if (!Context.Options.Deserialization.IgnoreArrayItemNames)
                            throw new InvalidItemNameDeserializationException(node.Name, itemName);
                    }

                }
                var value = ValueFactory.Create(_itemType);
                NodeFactory.CreateDeserializable(named ? Name : null, value, this, Context).Configure(modify);
                _list.Value.Add(value.Instance);
            }
        }