/// <inheritdoc/> public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value) { if (!NotifyNodeConstructing(containerDescriptor, member)) { return; } // If this member should contains a reference, create it now. IReference reference = CreateReferenceForNode(member.Type, value); ModelNode containerNode = GetContextNode(); ITypeDescriptor typeDescriptor = TypeDescriptorFactory.Find(member.Type); IContent content = new MemberContent(containerNode.Content, member, typeDescriptor, IsPrimitiveType(member.Type), reference); var node = new ModelNode(member.Name, content, Guid.NewGuid()); containerNode.AddChild(node); if (reference != null) { referenceContents.Add(content); } if (!(reference is ObjectReference)) { // For enumerable references, we visit the member to allow VisitCollection or VisitDictionary to enrich correctly the node. PushContextNode(node); Visit(value); PopContextNode(); } AvailableCommands.Where(x => x.CanAttach(node.Content.Descriptor, (MemberDescriptorBase)member)).ForEach(node.AddCommand); NotifyNodeConstructed(content); node.Seal(); }
/// <inheritdoc/> public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value) { bool shouldProcessReference; if (!NotifyNodeConstructing(containerDescriptor, member, out shouldProcessReference)) { return; } // If this member should contains a reference, create it now. GraphNode containerNode = GetContextNode(); IContent content = ContentFactory.CreateMemberContent(this, containerNode.Content, member, IsPrimitiveType(member.Type), value, shouldProcessReference); var node = (GraphNode)currentNodeFactory(member.Name, content, Guid.NewGuid()); containerNode.AddChild(node); if (content.IsReference) { referenceContents.Add(content); } PushContextNode(node); if (!(content.Reference is ObjectReference)) { // For enumerable references, we visit the member to allow VisitCollection or VisitDictionary to enrich correctly the node. Visit(content.Value); } PopContextNode(); AvailableCommands.Where(x => x.CanAttach(node.Content.Descriptor, (MemberDescriptorBase)member)).ForEach(node.AddCommand); NotifyNodeConstructed(content); node.Seal(); }
/// <inheritdoc/> public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value) { // If this member should contains a reference, create it now. var containerNode = (IInitializingObjectNode)GetContextNode(); var guid = Guid.NewGuid(); var content = (MemberContent)ContentFactory.CreateMemberContent(this, guid, containerNode, member, IsPrimitiveType(member.Type), value); containerNode.AddMember(content); if (content.IsReference) { referenceContents.Add(content); } PushContextNode(content); if (content.TargetReference == null) { // For enumerable references, we visit the member to allow VisitCollection or VisitDictionary to enrich correctly the node. Visit(content.Value); } PopContextNode(); AvailableCommands.Where(x => x.CanAttach(content.Descriptor, (MemberDescriptorBase)member)).ForEach(content.AddCommand); content.Seal(); }
/// <inheritdoc/> public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers) { ITypeDescriptor currentDescriptor = descriptor; bool isRootNode = contextStack.Count == 0; if (isRootNode) { bool shouldProcessReference; if (!NotifyNodeConstructing(descriptor, out shouldProcessReference)) { return; } // If we are in the case of a collection of collections, we might have a root node that is actually an enumerable reference // This would be the case for each collection within the base collection. IContent content = descriptor.Type.IsStruct() ? ContentFactory.CreateBoxedContent(this, obj, descriptor, IsPrimitiveType(descriptor.Type)) : ContentFactory.CreateObjectContent(this, obj, descriptor, IsPrimitiveType(descriptor.Type), shouldProcessReference); currentDescriptor = content.Descriptor; rootNode = (GraphNode)currentNodeFactory(currentDescriptor.Type.Name, content, rootGuid); 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); NotifyNodeConstructed(content); if (obj == null) { rootNode.Seal(); return; } PushContextNode(rootNode); } if (!IsPrimitiveType(currentDescriptor.Type)) { base.VisitObject(obj, descriptor, true); } if (isRootNode) { PopContextNode(); rootNode.Seal(); } }
/// <inheritdoc/> public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers) { bool isRootNode = contextStack.Count == 0; if (isRootNode) { if (!NotifyNodeConstructing(descriptor)) { return; } // If we are in the case of a collection of collections, we might have a root node that is actually an enumerable reference // This would be the case for each collection within the base collection. IReference reference = CreateReferenceForNode(descriptor.Type, obj); reference = reference is ReferenceEnumerable ? reference : null; IContent content = descriptor.Type.IsStruct() ? new BoxedContent(obj, descriptor, IsPrimitiveType(descriptor.Type)) : new ObjectContent(obj, descriptor, IsPrimitiveType(descriptor.Type), reference); rootNode = new ModelNode(descriptor.Type.Name, content, rootGuid); if (reference != null && descriptor.Type.IsStruct()) { throw new QuantumConsistencyException("A collection type", "A structure type", rootNode); } if (reference != null) { referenceContents.Add(content); } AvailableCommands.Where(x => x.CanAttach(rootNode.Content.Descriptor, null)).ForEach(rootNode.AddCommand); NotifyNodeConstructed(content); if (obj == null) { rootNode.Seal(); return; } PushContextNode(rootNode); } if (!IsPrimitiveType(descriptor.Type)) { base.VisitObject(obj, descriptor, true); } if (isRootNode) { PopContextNode(); rootNode.Seal(); } }
/// <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(); } }