本文整理汇总了C#中NodeContainer类的典型用法代码示例。如果您正苦于以下问题:C# NodeContainer类的具体用法?C# NodeContainer怎么用?C# NodeContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeContainer类属于命名空间,在下文中一共展示了NodeContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSimpleObject
public void TestSimpleObject()
{
var nodeContainer = new NodeContainer();
var instance = new SimpleClass { Member1 = 3, Member2 = new SimpleClass() };
var rootNode = nodeContainer.GetOrCreateNode(instance);
var visitor = new TestVisitor();
visitor.Visit(rootNode);
var expectedNodes = new[]
{
rootNode,
rootNode.TryGetChild(nameof(SimpleClass.Member1)),
rootNode.TryGetChild(nameof(SimpleClass.Member2)),
rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target,
rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target.TryGetChild(nameof(SimpleClass.Member1)),
rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target.TryGetChild(nameof(SimpleClass.Member2)),
};
var expectedPaths = new[]
{
new GraphNodePath(rootNode),
new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member1)),
new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)),
new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget(),
new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget().PushMember(nameof(SimpleClass.Member1)),
new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget().PushMember(nameof(SimpleClass.Member2)),
};
VerifyNodesAndPath(expectedNodes, expectedPaths, visitor);
}
示例2: TestConstruction
public void TestConstruction()
{
var obj = new ClassWithStructs();
var container = new NodeContainer();
container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct));
IGraphNode model = container.GetOrCreateNode(obj);
Helper.PrintModelContainerContent(container, model);
// Members should never have children
Assert.That(model.GetChild("PrimitiveStruct").Children.Count, Is.EqualTo(0));
// Primitive struct has been registered as a primitive type, so it should not hold a reference.
Assert.Null(model.GetChild("PrimitiveStruct").Content.Reference);
// Members should never have children.
Assert.That(model.GetChild("NestedStruct").Children.Count, Is.EqualTo(0));
// NestedStruct members should be accessible via a reference.
Assert.NotNull(model.GetChild("NestedStruct").Content.Reference);
// The referenced node must exist.
var structNode = model.GetChild("NestedStruct").Content.Reference.AsObject.TargetNode;
Assert.NotNull(structNode);
// It should have two children, as the NestedStruct has.
Assert.That(structNode.Children.Count, Is.EqualTo(2));
// Similarly, the Struct member of the NestedStruct should hold a reference.
Assert.NotNull(structNode.GetChild("Struct").Content.Reference);
// The referenced node must exist.
structNode = structNode.GetChild("Struct").Content.Reference.AsObject.TargetNode;
Assert.NotNull(structNode);
// It should have two children, as the SimpleStruct has.
Assert.That(structNode.Children.Count, Is.EqualTo(2));
// Finally, we run the ModelConsistencyCheckVisitor to detect potential other issues.
Helper.ConsistencyCheck(container, obj);
}
示例3: TestReferenceMember
public void TestReferenceMember()
{
var obj = new ReferenceMember { Member = new StringMember { Member = "a" } };
var container = new NodeContainer();
var node = container.GetOrCreateNode(obj);
Assert.AreEqual(obj, node.Content.Value);
Assert.AreEqual(1, node.Children.Count);
Assert.AreEqual(nameof(ReferenceMember.Member), node.Children.First().Name);
Assert.AreEqual(obj.Member, node.Children.First().Content.Value);
Assert.AreEqual(true, node.Children.First().Content.IsReference);
Assert.IsInstanceOf<ObjectReference>(node.Children.First().Content.Reference);
var reference = (ObjectReference)node.Children.First().Content.Reference;
Assert.AreEqual(obj.Member, reference.ObjectValue);
Assert.IsNotNull(reference.TargetNode);
Assert.AreEqual(obj.Member, reference.TargetNode.Content.Value);
node = reference.TargetNode;
Assert.AreEqual(obj.Member, node.Content.Value);
Assert.AreEqual(1, node.Children.Count);
Assert.AreEqual(nameof(StringMember.Member), node.Children.First().Name);
Assert.AreEqual(obj.Member.Member, node.Children.First().Content.Value);
obj.Member.Member = "b";
Assert.AreEqual(obj.Member.Member, node.Children.First().Content.Value);
node.Children.First().Content.Update("c");
Assert.AreEqual(obj.Member.Member, node.Children.First().Content.Value);
}
示例4: TestObjectReferenceUpdate
public void TestObjectReferenceUpdate()
{
var nodeContainer = new NodeContainer();
var instance = new TestObject { Name = "Test" };
var container = new ObjectContainer { Instance = instance };
var containerNode = nodeContainer.GetOrCreateNode(container);
var memberNode = containerNode.Children.First();
var instanceNode = memberNode.Content.Reference.AsObject.TargetNode;
// Update to a new instance
var newInstance = new TestObject { Name = "Test2" };
memberNode.Content.Update(newInstance);
Helper.TestMemberContentNode(containerNode, memberNode, container, newInstance, nameof(ObjectContainer.Instance), true);
Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstance, false);
var newInstanceNode = nodeContainer.GetNode(newInstance);
Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstanceNode, newInstance);
Assert.AreNotEqual(instanceNode.Guid, newInstanceNode.Guid);
// Update to null
memberNode.Content.Update(null);
Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true);
Helper.TestNullObjectReference(memberNode.Content.Reference);
// Update back to the initial instance
memberNode.Content.Update(instance);
Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true);
Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance);
}
示例5: TestClone
public void TestClone()
{
var obj = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
var nodeContainer = new NodeContainer();
var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj));
var clone = path1.Clone();
AssertAreEqual(path1, clone);
AssertAreEqual(path1.GetHashCode(), clone.GetHashCode());
AssertAreEqual(path1.RootNode, clone.RootNode);
AssertAreEqual(path1.IsValid, clone.IsValid);
AssertAreEqual(path1.IsEmpty, clone.IsEmpty);
AssertAreEqual(path1.GetNode(), clone.GetNode());
var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
clone = path2.Clone();
AssertAreEqual(path2, clone);
AssertAreEqual(path2.RootNode, clone.RootNode);
AssertAreEqual(path2.IsValid, clone.IsValid);
AssertAreEqual(path2.IsEmpty, clone.IsEmpty);
AssertAreEqual(path2.GetNode(), clone.GetNode());
var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
clone = path3.Clone();
AssertAreEqual(path3, clone);
AssertAreEqual(path3.RootNode, clone.RootNode);
AssertAreEqual(path3.IsValid, clone.IsValid);
AssertAreEqual(path3.IsEmpty, clone.IsEmpty);
AssertAreEqual(path3.GetNode(), clone.GetNode());
}
示例6: TestCloneNewRoot
public void TestCloneNewRoot()
{
var obj1 = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
var obj2 = new Class { ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } };
var nodeContainer = new NodeContainer();
var newRoot = nodeContainer.GetOrCreateNode(obj2);
var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj1));
var clone = path1.Clone(newRoot);
Assert.AreNotEqual(newRoot, path1.RootNode);
Assert.AreEqual(newRoot, clone.RootNode);
Assert.AreEqual(path1.IsValid, clone.IsValid);
Assert.AreEqual(path1.IsEmpty, clone.IsEmpty);
var path2 = path1.PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember));
clone = path2.Clone(newRoot);
Assert.AreNotEqual(newRoot, path2.RootNode);
Assert.AreEqual(newRoot, clone.RootNode);
Assert.AreEqual(path2.IsValid, clone.IsValid);
Assert.AreEqual(path2.IsEmpty, clone.IsEmpty);
var path3 = path1.PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember));
clone = path3.Clone(newRoot);
Assert.AreNotEqual(newRoot, path3.RootNode);
Assert.AreEqual(newRoot, clone.RootNode);
Assert.AreEqual(path3.IsValid, clone.IsValid);
Assert.AreEqual(path3.IsEmpty, clone.IsEmpty);
}
示例7: UploadNodes
public void UploadNodes(NodeContainer nodes)
{
// for large sets of nodes, this shoud be async with ListBlobsSegmentedAsync
foreach (var node in nodes)
{
this.UploadNode(node);
}
}
示例8: MemberContent
public MemberContent(INodeBuilder nodeBuilder, IContent container, IMemberDescriptor member, bool isPrimitive, IReference reference)
: base(nodeBuilder.TypeDescriptorFactory.Find(member.Type), isPrimitive, reference)
{
if (container == null) throw new ArgumentNullException(nameof(container));
Member = member;
Container = container;
nodeContainer = nodeBuilder.NodeContainer;
}
示例9: SearchPathSuccess
public void SearchPathSuccess()
{
var nodes = new NodeContainer
{
new Node()
{
id = 1,
adjacentNodes = new int[] {2, 3},
label = "top"
},
new Node()
{
id = 2,
adjacentNodes = new int[] {1},
label = "second"
},
new Node()
{
id = 3,
adjacentNodes = new int[] {1, 5, 4},
label = "second"
},
new Node()
{
id = 4,
adjacentNodes = new int[] {3},
label = "second"
},
new Node()
{
id = 5,
adjacentNodes = new int[] {3},
label = "blind"
},
new Node()
{
id = 6,
adjacentNodes = new int[] {4},
label = "end"
},
new Node()
{
id = 7,
adjacentNodes = new int[] {1},
label = "blind"
},
};
var graphService = new Graph();
graphService.MakeAdjactedBothWay(nodes);
var search = new SearchPath(nodes);
var result = search.ShortestPath(1, 6);
Assert.AreEqual(new int[] {6,4,3}, result);
}
示例10: TestChangeBoxedPrimitiveMember
public void TestChangeBoxedPrimitiveMember()
{
var nodeContainer = new NodeContainer();
var instance = new ComplexClass { Member3 = 3 };
var rootNode = nodeContainer.GetOrCreateNode(instance);
var listener = new GraphNodeChangeListener(rootNode);
var node = rootNode.TryGetChild(nameof(ComplexClass.Member3));
TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, 3, 4, () => node.Content.Update(4));
TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, 4, 5, () => node.Content.Update(5));
}
示例11: ConsistencyCheck
public static void ConsistencyCheck(NodeContainer container, object rootObject)
{
var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
var model = container.GetNode(rootObject);
visitor.Check((GraphNode)model, rootObject, rootObject.GetType(), true);
foreach (var node in container.Nodes)
{
visitor.Check((GraphNode)node, node.Content.Value, node.Content.Type, true);
}
}
示例12: TestConstructor
public void TestConstructor()
{
var obj = new Class();
var nodeContainer = new NodeContainer();
var rootNode = nodeContainer.GetOrCreateNode(obj);
var path = new GraphNodePath(rootNode);
Assert.True(path.IsValid);
Assert.True(path.IsEmpty);
Assert.AreEqual(rootNode, path.RootNode);
}
示例13: TestNullObjectReference
public void TestNullObjectReference()
{
var nodeContainer = new NodeContainer();
var container = new ObjectContainer { Instance = null };
var containerNode = nodeContainer.GetOrCreateNode(container);
Helper.TestNonCollectionObjectContentNode(containerNode, container, 1);
var memberNode = containerNode.Children.First();
Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true);
Helper.TestNullObjectReference(memberNode.Content.Reference);
}
示例14: TestChangeReferenceMemberToNull
public void TestChangeReferenceMemberToNull()
{
var nodeContainer = new NodeContainer();
var obj = new[] { new SimpleClass(), null, new SimpleClass() };
var instance = new ComplexClass { Member2 = obj[0] };
var rootNode = nodeContainer.GetOrCreateNode(instance);
var listener = new GraphNodeChangeListener(rootNode);
var node = rootNode.TryGetChild(nameof(ComplexClass.Member2));
TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[0], obj[1], () => node.Content.Update(obj[1]));
TestContentChange(listener, node, ContentChangeType.ValueChange, Index.Empty, obj[1], obj[2], () => node.Content.Update(obj[2]));
}
示例15: MakeAdjactedBothWay
public void MakeAdjactedBothWay(NodeContainer nodes)
{
foreach (var node in nodes)
{
foreach (var adjacted in node.adjacentNodes)
{
var adjNode = nodes.GetNode(adjacted);
var corrected = adjNode.adjacentNodes.Concat(new[] {node.id}).ToArray();
adjNode.adjacentNodes = corrected;
}
}
}