コード例 #1
0
 /// <summary>
 /// Reset the visitor in order to use it to generate another model.
 /// </summary>
 public override void Reset()
 {
     rootNode = null;
     rootGuid = Guid.Empty;
     contextStack.Clear();
     referenceContents.Clear();
     base.Reset();
 }
コード例 #2
0
        /// <inheritdoc/>
        public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)
        {
            ITypeDescriptor currentDescriptor = descriptor;

            bool isRootNode = contextStack.Count == 0;

            if (isRootNode)
            {
                // If we're visiting a value type as "object" we need to use a special "boxed" node.
                var content = descriptor.Type.IsValueType ? ContentFactory.CreateBoxedContent(this, rootGuid, obj, descriptor, IsPrimitiveType(descriptor.Type))
                    : ContentFactory.CreateObjectContent(this, rootGuid, obj, descriptor, IsPrimitiveType(descriptor.Type));

                currentDescriptor = content.Descriptor;
                rootNode          = (IInitializingObjectNode)content;
                if (content.IsReference && currentDescriptor.Type.IsStruct())
                {
                    throw new QuantumConsistencyException("A collection type", "A structure type", rootNode);
                }

                if (content.IsReference)
                {
                    referenceContents.Add(content);
                }

                AvailableCommands.Where(x => x.CanAttach(currentDescriptor, null)).ForEach(rootNode.AddCommand);

                if (obj == null)
                {
                    rootNode.Seal();
                    return;
                }
                PushContextNode(rootNode);
            }

            if (!IsPrimitiveType(currentDescriptor.Type))
            {
                base.VisitObject(obj, descriptor, true);
            }

            if (isRootNode)
            {
                PopContextNode();
                rootNode.Seal();
            }
        }