Esempio n. 1
0
        protected override void AddChild(SchemaMemberBase child)
        {
            if (!(child is SchemaMember schema))
            {
                throw new ArgumentNullException();
            }

            if (_children == null)
            {
                System.Threading.Interlocked.CompareExchange(ref _children, new NamedCollection <SchemaMember>(item => item.Name), null);
            }

            _children.Add(schema);
            schema._parent = this;
        }
            public StateContext(int length, Func <SchemaEntryToken, IEnumerable <TMember> > mapper, Action <string> onError, object data, Collections.INamedCollection <TMember> members)
            {
                _bufferIndex = 0;
                _buffer      = new char[length];
                _current     = null;
                _mapper      = mapper;
                _onError     = onError;
                _token       = new SchemaEntryToken(data);
                _stack       = new Stack <SchemaMemberBase>();

                this.Character = '\0';
                this.State     = State.None;
                this.Flags     = new StateVector();

                _members = members ?? new Collections.NamedCollection <TMember>(item => item.Name, StringComparer.OrdinalIgnoreCase);
            }
            private void Map(string name, SchemaMemberBase parent)
            {
                //重置当前段
                _current = null;

                _token.Name   = name;
                _token.Parent = (TMember)parent;

                var items = _mapper(_token);

                if (items == null)
                {
                    return;
                }

                if (_token.Parent == null)
                {
                    foreach (var item in items)
                    {
                        if (_members.Contains(item.Name))
                        {
                            _current = item;
                        }
                        else
                        {
                            _members.Add((TMember)(_current = item));
                        }
                    }
                }
                else
                {
                    foreach (var item in items)
                    {
                        if (_token.Parent.TryGetChild(item.Name, out _))
                        {
                            _current = item;
                        }
                        else
                        {
                            _token.Parent.AddChild(_current = item);
                        }
                    }
                }
            }
            public void Include(string name = null)
            {
                var     parent = this.Peek();
                TMember current;

                if (string.IsNullOrEmpty(name))
                {
                    if (_bufferIndex == 0)
                    {
                        return;
                    }

                    name = this.GetBuffer();
                }

                if (parent == null)
                {
                    if (_members.TryGet(name, out current))
                    {
                        _current = current;
                    }
                    else
                    {
                        this.Map(name, null);
                    }
                }
                else
                {
                    //如果是忽略段则不需要进行子集和映射处理
                    if (object.ReferenceEquals(parent, SchemaMemberBase.Ignores))
                    {
                        return;
                    }

                    if (parent.TryGetChild(name, out var child))
                    {
                        _current = child;
                    }
                    else
                    {
                        this.Map(name, parent);
                    }
                }
            }
Esempio n. 5
0
 protected override void SetParent(SchemaMemberBase parent)
 {
     _parent = (parent as SchemaMember) ?? throw new ArgumentException();
 }
Esempio n. 6
0
 protected internal override bool TryGetChild(string name, out SchemaMemberBase child)
 {
     child = null;
     return(false);
 }
Esempio n. 7
0
 protected internal override void AddChild(SchemaMemberBase child)
 {
 }
Esempio n. 8
0
 protected override void SetParent(SchemaMemberBase parent)
 {
 }
Esempio n. 9
0
 internal protected abstract void AddChild(SchemaMemberBase child);
Esempio n. 10
0
 internal protected abstract bool TryGetChild(string name, out SchemaMemberBase child);
Esempio n. 11
0
 protected abstract void SetParent(SchemaMemberBase parent);