예제 #1
0
        public void Serialize <T>(IWriteVisitor visitor, T graph)
        {
            if (visitor == null)
            {
                throw new ArgumentNullException(nameof(visitor));
            }
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }

            var traveller = _rootTravellers.GetOrAdd <T>(out var level);

            if (level == LevelType.Value)
            {
                var valueVisitor = ValueVisitor.Create <T>();
                valueVisitor.VisitValue(visitor, VisitArgs.CreateRoot(level), graph);
            }
            else
            {
                var rootArgs = VisitArgs.CreateRoot(level);
                visitor.Visit(graph, rootArgs);
                traveller.Travel(visitor, graph);
                visitor.Leave(graph, rootArgs);
            }
        }
예제 #2
0
        public void Visit(object graph, IWriteVisitor visitor)
        {
            var childGraph = _property.Ref.GetValue(graph);
            visitor.Visit(childGraph, _args);
            if (childGraph == null) {
                visitor.Leave(null, _args);
                return;
            }

            _propertyType.Visit(childGraph, visitor);
            visitor.Leave(childGraph, _args);
        }
예제 #3
0
        public void Travel(IWriteVisitor visitor, MultidimensionalArrayGraph graph)
        {
            {
                var c = graph.Value;
                visitor.Visit(c, _argsValue);

                if (c != null)
                {
                    for (var r0 = 0; r0 < c.GetLength(0); r0++)
                    {
                        visitor.Visit(c, VisitArgs.CollectionInCollection);
                        for (var r1 = 0; r1 < c.GetLength(1); r1++)
                        {
                            visitor.VisitValue(c[r0, r1], VisitArgs.CollectionItem);
                        }
                        visitor.Leave(c, VisitArgs.CollectionInCollection);
                    }
                }

                visitor.Leave(c, _argsValue);
            }
        }
예제 #4
0
        public void Visit(object graph, IWriteVisitor visitor)
        {
            var childGraph = _property.Ref.GetValue(graph);

            visitor.Visit(childGraph, _args);
            if (childGraph == null)
            {
                visitor.Leave(null, _args);
                return;
            }

            _propertyType.Visit(childGraph, visitor);
            visitor.Leave(childGraph, _args);
        }
예제 #5
0
        public void Travel(IWriteVisitor visitor, TDictionary graph)
        {
            var valueArgs = VisitArgs.DictionaryValue;

            void TravelValue(TValue value)
            {
                if (_valueVisitor != null)
                {
                    _valueVisitor.VisitValue(visitor, valueArgs, value);
                    return;
                }

                visitor.Visit(value, valueArgs);
                _valueTraveller.Travel(visitor, value);
                visitor.Leave(value, valueArgs);
            }

            var keyArgs = VisitArgs.DictionaryKey;

            foreach (var kv in graph)
            {
                if (_keyVisitor != null)
                {
                    _keyVisitor.VisitValue(visitor, keyArgs, kv.Key);
                    TravelValue(kv.Value);
                }
                else
                {
                    var key = kv.Key;
                    visitor.Visit(key, keyArgs);
                    _keyTraveller.Travel(visitor, key);
                    visitor.Leave(key, keyArgs);
                    TravelValue(kv.Value);
                }
            }
        }
예제 #6
0
        public void Travel(IWriteVisitor visitor, TCollection graph)
        {
            var itemArgs = VisitArgs.CollectionItem;

            foreach (var element in graph)
            {
                if (_valueVisitor != null)
                {
                    _valueVisitor.VisitValue(visitor, itemArgs, element);
                }
                else
                {
                    visitor.Visit(element, itemArgs);
                    _elementTraveller.Travel(visitor, element);
                    visitor.Leave(element, itemArgs);
                }
            }
        }
예제 #7
0
        public void Travel(IWriteVisitor visitor, DataBlock graph)
        {
            visitor.VisitValue(graph.Id, _argsId);
            visitor.VisitValue(graph.String, _argsString);
            visitor.VisitValue(graph.Int16, _argsInt16);
            visitor.VisitValue(graph.Int32, _argsInt32);
            visitor.VisitValue(graph.Int64, _argsInt64);
            visitor.VisitValue(graph.UInt16, _argsUInt16);
            visitor.VisitValue(graph.UInt32, _argsUInt32);
            visitor.VisitValue(graph.UInt64, _argsUInt64);
            visitor.VisitValue(graph.Single, _argsSingle);
            visitor.VisitValue(graph.Double, _argsDouble);
            visitor.VisitValue(graph.TimeSpan, _argsTimeSpan);
            visitor.VisitValue(graph.Decimal, _argsDecimal);
            visitor.VisitValue(graph.DateTime, _argsDateTime);
            visitor.VisitValue(graph.Byte, _argsByte);
            visitor.VisitValue(graph.Boolean, _argsBoolean);
            visitor.VisitValue(graph.Blob, _argsBlob);

            {
                var c = graph.Messages;
                visitor.Visit(c, _argsMessages);

                if (c != null)
                {
                    foreach (var cv in c)
                    {
                        visitor.VisitValue(cv, VisitArgs.CollectionItem);
                    }
                }

                visitor.Leave(c, _argsMessages);
            }

            {
                var c = (ICollection <DateTime>)graph.Stamps;
                visitor.Visit(c, _argsStamps);
                if (c != null)
                {
                    foreach (var cv in c)
                    {
                        visitor.VisitValue(cv, VisitArgs.CollectionItem);
                    }
                }

                visitor.Leave(c, _argsStamps);
            }

            {
                var c = graph.Relation;
                visitor.Visit(c, _argsRelation);
                if (c != null)
                {
                    _travellerRelation0.Travel(visitor, c);
                }
                visitor.Leave(c, _argsRelation);
            }

            {
                var c = graph.DummyRelation;
                visitor.Visit(c, _argsDummyRelation);
                if (c != null)
                {
                    _travellerRelation0.Travel(visitor, c);
                }
                visitor.Leave(c, _argsDummyRelation);
            }

            {
                var c = (ICollection <Relation>)graph.SecondaryRelations;
                visitor.Visit(c, _argsSecondaryRelations);
                if (c != null)
                {
                    foreach (var cv in c)
                    {
                        visitor.Visit(cv, VisitArgs.CollectionItem);
                        _travellerRelation0.Travel(visitor, cv);
                        visitor.Leave(cv, VisitArgs.CollectionItem);
                    }
                }

                visitor.Leave(c, _argsSecondaryRelations);
            }

            {
                var c = (IDictionary <string, int>)graph.IndexedValues;
                visitor.Visit(c, _argsIndexedValues);
                if (c != null)
                {
                    foreach (var ckv in c)
                    {
                        visitor.VisitValue(ckv.Key, VisitArgs.DictionaryKey);
                        visitor.VisitValue(ckv.Value, VisitArgs.DictionaryValue);
                    }
                }
                visitor.Leave(c, _argsIndexedValues);
            }

            {
                var c = (IDictionary <Identifier, Category>)graph.Categories;
                visitor.Visit(c, _argsCategories);
                if (c != null)
                {
                    foreach (var ckv in c)
                    {
                        visitor.Visit(ckv.Key, VisitArgs.DictionaryKey);
                        _travellerIdentifier1.Travel(visitor, ckv.Key);
                        visitor.Leave(ckv.Key, VisitArgs.DictionaryKey);

                        visitor.Visit(ckv.Value, VisitArgs.DictionaryValue);
                        _travellerCategory2.Travel(visitor, ckv.Value);
                        visitor.Leave(ckv.Value, VisitArgs.DictionaryValue);
                    }
                }
                visitor.Leave(c, _argsCategories);
            }
        }