本文整理汇总了C#中DomNode.SetChild方法的典型用法代码示例。如果您正苦于以下问题:C# DomNode.SetChild方法的具体用法?C# DomNode.SetChild怎么用?C# DomNode.SetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomNode
的用法示例。
在下文中一共展示了DomNode.SetChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestOnChildRemoved
public void TestOnChildRemoved()
{
DomNode root = new DomNode(m_rootType);
Validator validator = root.As<Validator>();
DomNode child = new DomNode(m_childType);
root.SetChild(m_childInfo, child);
root.SetChild(m_childInfo, null);
Assert.AreSame(validator.Sender, root);
ChildEventArgs e = (ChildEventArgs)validator.E;
Assert.NotNull(e);
Assert.AreSame(e.Parent, root);
}
示例2: CreateTree
private DomNode CreateTree()
{
DomNode root = new DomNode(m_rootType);
DomNode child = new DomNode(m_childType);
DomNode grandchild = new DomNode(m_childType);
child.SetChild(m_childInfo, grandchild);
root.SetChild(m_childInfo, child);
return root;
}
示例3: CreateTree
protected DomNode CreateTree()
{
DomNode root = new DomNode(RootType);
DomNode child = new DomNode(ChildType);
DomNode grandchild = new DomNode(ChildType);
child.SetChild(ChildInfo, grandchild);
root.SetChild(ChildInfo, child);
return root;
}
示例4: TestParentChildren
public void TestParentChildren()
{
DomNodeType type = new DomNodeType("type");
ChildInfo childInfo1 = new ChildInfo("child1", type);
type.Define(childInfo1);
ChildInfo childInfo2 = new ChildInfo("child2", type, true);
type.Define(childInfo2);
DomNode child1 = new DomNode(type);
DomNode child2 = new DomNode(type);
DomNode parent = new DomNode(type);
parent.SetChild(childInfo1, child1);
parent.GetChildList(childInfo2).Add(child2);
Utilities.TestSequenceEqual(parent.Children, child1, child2);
}
示例5: TestGetRoots
public void TestGetRoots()
{
DomNodeType type = new DomNodeType("type");
ChildInfo childInfo = new ChildInfo("child", type);
type.Define(childInfo);
DomNode child = new DomNode(type);
DomNode parent = new DomNode(type);
DomNode grandparent = new DomNode(type);
parent.SetChild(childInfo, child);
grandparent.SetChild(childInfo, parent);
DomNode child2 = new DomNode(type);
Utilities.TestSequenceEqual(DomNode.GetRoots(new DomNode[] { grandparent, child, child2 }), grandparent, child2);
}
示例6: CreateTestCircuitProgrammatically
// Create circuit DOM hierarchy programmatically
static public DomNode CreateTestCircuitProgrammatically(SchemaLoader schemaLoader)
{
var rootNode = new DomNode(Schema.circuitDocumentType.Type, Schema.circuitRootElement);
// create an empty root prototype folder( required child by schema)
rootNode.SetChild(
Schema.circuitDocumentType.prototypeFolderChild,
new DomNode(Schema.prototypeFolderType.Type));
var circuit = rootNode.Cast<Circuit>();
var inputFiles = new DomNode(Schema.groupType.Type).Cast<Group>();
inputFiles.Id = "groupInputFiles";
inputFiles.Name = "Input Files".Localize();
inputFiles.Bounds = new Rectangle(64, 96, 0, 0); // set node location, size will be auto-computed
var firstWavgGroup = new DomNode(Schema.groupType.Type).Cast<Group>();
firstWavgGroup.Id = "first.Wav";
firstWavgGroup.Name = "first".Localize("as in, 'the first file'") + ".wav";
var buttonType = schemaLoader.GetNodeType(Schema.NS + ButtonTypeName);
var button1 = new DomNode(buttonType).Cast<Module>();
button1.Id = "button1";
button1.Bounds = new Rectangle(0, 0, 0, 0);
var button2 = new DomNode(buttonType).Cast<Module>();
button2.Bounds = new Rectangle(0, 64, 0, 0);
button2.Id = "button2";
firstWavgGroup.Elements.Add(button1);
firstWavgGroup.Elements.Add(button2);
firstWavgGroup.Expanded = true;
firstWavgGroup.Update();
var secondWavgGroup = new DomNode(Schema.groupType.Type).Cast<Group>();
secondWavgGroup.Id = "second.Wav";
secondWavgGroup.Name = "second".Localize("as in, 'the second file'") + ".wav";
var button3 = new DomNode(buttonType).Cast<Module>();
button3.Id = "button3";
button3.Bounds = new Rectangle(0, 0, 0, 0);
var button4 = new DomNode(buttonType).Cast<Module>();
button4.Bounds = new Rectangle(0, 64, 0, 0);
button4.Id = "button4";
secondWavgGroup.Elements.Add(button3);
secondWavgGroup.Elements.Add(button4);
secondWavgGroup.Expanded = true;
secondWavgGroup.Update();
secondWavgGroup.Bounds = new Rectangle(0, 224, 0, 0);
inputFiles.Elements.Add(firstWavgGroup);
inputFiles.Elements.Add(secondWavgGroup);
inputFiles.Update();
inputFiles.Expanded = true;
circuit.Elements.Add(inputFiles);
var structure = new DomNode(Schema.groupType.Type).Cast<Group>();
structure.Id = "structure".Localize("this is the name of a group of circuit elements; the name is arbitrary");
structure.Name = "structure".Localize("this is the name of a group of circuit elements; the name is arbitrary");
structure.Bounds = new Rectangle(352, 96, 0, 0);
var subStream0 = new DomNode(Schema.groupType.Type).Cast<Group>();
subStream0.Id = "subStream0".Localize("this is the name of a group of circuit elements; the name is arbitrary");
subStream0.Name = "sub-stream 0".Localize("this is the name of a group of circuit elements; the name is arbitrary");
var lightType = schemaLoader.GetNodeType(Schema.NS + LightTypeName);
var light1 = new DomNode(lightType).Cast<Module>();
light1.Id = "light1";
light1.Bounds = new Rectangle(0, 0, 0, 0);
var light2 = new DomNode(lightType).Cast<Module>();
light2.Id = "light2";
light2.Bounds = new Rectangle(0, 64, 0, 0);
var light3 = new DomNode(lightType).Cast<Module>();
light3.Id = "light3";
light3.Bounds = new Rectangle(0, 128, 0, 0);
var light4 = new DomNode(lightType).Cast<Module>();
light4.Id = "light4";
light4.Bounds = new Rectangle(0, 192, 0, 0);
var light5 = new DomNode(lightType).Cast<Module>();
light5.Id = "light5";
light5.Bounds = new Rectangle(0, 256, 0, 0);
var light6 = new DomNode(lightType).Cast<Module>();
light6.Id = "light6";
light6.Bounds = new Rectangle(0, 320, 0, 0);
subStream0.Elements.Add(light1);
subStream0.Elements.Add(light2);
//.........这里部分代码省略.........
示例7: Deserialize
private static DomNode Deserialize(BinaryReader reader, Func<string, DomNodeType> getNodeType, List<Reference> references)
{
string typeName = reader.ReadString();
DomNodeType type = getNodeType(typeName);
if (type == null)
throw new InvalidOperationException("unknown node type");
DomNode node = new DomNode(type);
foreach (AttributeInfo info in type.Attributes)
{
bool hasAttribute = reader.ReadBoolean();
if (hasAttribute)
{
// references are reconstituted after all nodes are read
if (info.Type.Type == AttributeTypes.Reference)
{
int refId = reader.ReadInt32();
references.Add(new Reference(node, info, refId));
}
else
{
string valueString = reader.ReadString();
object value = info.Type.Convert(valueString);
node.SetAttribute(info, value);
}
}
}
foreach (ChildInfo info in type.Children)
{
if (info.IsList)
{
int count = reader.ReadInt32();
IList<DomNode> childList = node.GetChildList(info);
for (int i = 0; i < count; i++)
{
DomNode child = Deserialize(reader, getNodeType, references);
childList.Add(child);
}
}
else
{
bool hasChild = reader.ReadBoolean();
if (hasChild)
{
DomNode child = Deserialize(reader, getNodeType, references);
node.SetChild(info, child);
}
}
}
return node;
}
示例8: ReadElement
/// <summary>
/// Reads the node specified by the child metadata</summary>
/// <param name="nodeInfo">Child metadata for node</param>
/// <param name="reader">XML reader</param>
/// <returns>DomNode specified by the child metadata</returns>
protected virtual DomNode ReadElement(ChildInfo nodeInfo, XmlReader reader)
{
// handle polymorphism, if necessary
DomNodeType type = GetChildType(nodeInfo.Type, reader);
int index = type.Name.LastIndexOf(':');
string typeNS = type.Name.Substring(0, index);
DomNode node = new DomNode(type, nodeInfo);
// read attributes
while (reader.MoveToNextAttribute())
{
if (reader.Prefix == string.Empty ||
reader.LookupNamespace(reader.Prefix) == typeNS)
{
AttributeInfo attributeInfo = type.GetAttributeInfo(reader.LocalName);
if (attributeInfo != null)
{
string valueString = reader.Value;
if (attributeInfo.Type.Type == AttributeTypes.Reference)
{
// save reference so it can be resolved after all nodes have been read
m_nodeReferences.Add(new XmlNodeReference(node, attributeInfo, valueString));
}
else
{
object value = attributeInfo.Type.Convert(valueString);
node.SetAttribute(attributeInfo, value);
}
}
}
}
// add node to map if it has an id
if (node.Type.IdAttribute != null)
{
string id = node.GetId();
if (!string.IsNullOrEmpty(id))
m_nodeDictionary[id] = node; // don't Add, in case there are multiple DomNodes with the same id
}
reader.MoveToElement();
if (!reader.IsEmptyElement)
{
// read child elements
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
// look up metadata for this element
ChildInfo childInfo = type.GetChildInfo(reader.LocalName);
if (childInfo != null)
{
DomNode childObject = ReadElement(childInfo, reader);
// at this point, child is a fully populated sub-tree
if (childInfo.IsList)
{
node.GetChildList(childInfo).Add(childObject);
}
else
{
node.SetChild(childInfo, childObject);
}
}
else
{
// try reading as an attribute
AttributeInfo attributeInfo = type.GetAttributeInfo(reader.LocalName);
if (attributeInfo != null)
{
reader.MoveToElement();
if (!reader.IsEmptyElement)
{
// read element text
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Text)
{
object value = attributeInfo.Type.Convert(reader.Value);
node.SetAttribute(attributeInfo, value);
// skip child elements, as this is an attribute value
reader.Skip();
break;
}
if (reader.NodeType == XmlNodeType.EndElement)
{
break;
}
}
reader.MoveToContent();
}
//.........这里部分代码省略.........
示例9: Open
/// <summary>
/// Opens or creates a document at the given URI. Create an AdaptableControl with control adapters for viewing state machine.
/// Handles application data persistence.</summary>
/// <param name="uri">Document URI</param>
/// <returns>Document, or null if the document couldn't be opened or created</returns>
public IDocument Open(Uri uri)
{
DomNode node = null;
string filePath = uri.LocalPath;
string fileName = Path.GetFileName(filePath);
if (File.Exists(filePath))
{
// read existing document using standard XML reader
using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
DomXmlReader reader = new DomXmlReader(m_schemaLoader);
node = reader.Read(stream, uri);
}
}
else
{
// create new document by creating a Dom node of the root type defined by the schema
node = new DomNode(Schema.fsmType.Type, Schema.fsmRootElement);
// create an empty root prototype folder
node.SetChild(
Schema.fsmType.prototypeFolderChild,
new DomNode(Schema.prototypeFolderType.Type));
}
Document document = null;
if (node != null)
{
// set up the AdaptableControl for editing FSMs
var control = new D2dAdaptableControl();
control.SuspendLayout();
control.BackColor = SystemColors.ControlLight;
control.AllowDrop = true;
var transformAdapter = new TransformAdapter(); // required by several of the other adapters
transformAdapter.UniformScale = true;
transformAdapter.MinScale = new PointF(0.25f, 0.25f);
transformAdapter.MaxScale = new PointF(4, 4);
var viewingAdapter = new ViewingAdapter(transformAdapter); // implements IViewingContext for framing or ensuring that items are visible
var canvasAdapter = new CanvasAdapter(); // implements a bounded canvas to limit scrolling
var autoTranslateAdapter = // implements auto translate when the user drags out of control's client area
new AutoTranslateAdapter(transformAdapter);
var mouseTransformManipulator = // implements mouse drag translate and scale
new MouseTransformManipulator(transformAdapter);
var mouseWheelManipulator = // implements mouse wheel scale
new MouseWheelManipulator(transformAdapter);
var scrollbarAdapter = // adds scroll bars to control, driven by canvas and transform
new ScrollbarAdapter(transformAdapter, canvasAdapter);
var hoverAdapter = new HoverAdapter(); // add hover events over pickable items
hoverAdapter.HoverStarted += control_HoverStarted;
hoverAdapter.HoverStopped += control_HoverStopped;
var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram
var fsmAdapter = // adapt control to allow binding to graph data
new D2dGraphAdapter<State, Transition, NumberedRoute>(m_fsmRenderer, transformAdapter);
var fsmStateEditAdapter = // adapt control to allow state editing
new D2dGraphNodeEditAdapter<State, Transition, NumberedRoute>(m_fsmRenderer, fsmAdapter, transformAdapter);
var fsmTransitionEditAdapter = // adapt control to allow transition
new D2dGraphEdgeEditAdapter<State, Transition, NumberedRoute>(m_fsmRenderer, fsmAdapter, transformAdapter);
var mouseLayoutManipulator = new MouseLayoutManipulator(transformAdapter);
// apply adapters to control; ordering is from back to front, that is, the first adapter
// will be conceptually underneath all the others. Mouse and keyboard events are fed to
// the adapters in the reverse order, so it all makes sense to the user.
control.Adapt(
hoverAdapter,
scrollbarAdapter,
autoTranslateAdapter,
new RectangleDragSelector(),
transformAdapter,
viewingAdapter,
canvasAdapter,
mouseTransformManipulator,
mouseWheelManipulator,
new KeyboardGraphNavigator<State, Transition, NumberedRoute>(),
//new GridAdapter(),
annotationAdaptor,
fsmAdapter,
fsmStateEditAdapter,
fsmTransitionEditAdapter,
new LabelEditAdapter(),
new SelectionAdapter(),
mouseLayoutManipulator,
new DragDropAdapter(m_statusService),
new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
);
//.........这里部分代码省略.........
示例10: TestChildRemoveEvents
public void TestChildRemoveEvents()
{
DomNodeType type = new DomNodeType("type");
ChildInfo info = new ChildInfo("child", type);
ChildInfo infoList = new ChildInfo("childList", type, true);
type.Define(info);
type.Define(infoList);
DomNode test = new DomNode(type);
test.ChildRemoving += new EventHandler<ChildEventArgs>(test_ChildRemoving);
test.ChildRemoved += new EventHandler<ChildEventArgs>(test_ChildRemoved);
// test child
DomNode child = new DomNode(type);
test.SetChild(info, child);
ChildRemovingArgs = null;
ChildRemovedArgs = null;
test.SetChild(info, null);
ChildEventArgs expected = new ChildEventArgs(test, info, child, 0);
Assert.True(Equals(ChildRemovingArgs, expected));
Assert.True(Equals(ChildRemovedArgs, expected));
// test inserting a child when there is one there already
test.SetChild(info, child);
DomNode newChild = new DomNode(type);
ChildRemovingArgs = null;
ChildRemovedArgs = null;
test.SetChild(info, newChild);
expected = new ChildEventArgs(test, info, child, 0);
Assert.True(Equals(ChildRemovingArgs, expected));
Assert.True(Equals(ChildRemovedArgs, expected));
// test child list
IList<DomNode> list = test.GetChildList(infoList);
DomNode child2 = new DomNode(type);
list.Add(child2);
DomNode child3 = new DomNode(type);
list.Add(child3);
ChildRemovingArgs = null;
ChildRemovedArgs = null;
list.Remove(child3);
expected = new ChildEventArgs(test, infoList, child3, 1);
Assert.True(Equals(ChildRemovingArgs, expected));
Assert.True(Equals(ChildRemovedArgs, expected));
ChildRemovingArgs = null;
ChildRemovedArgs = null;
list.Remove(child2);
expected = new ChildEventArgs(test, infoList, child2, 0);
Assert.True(Equals(ChildRemovingArgs, expected));
Assert.True(Equals(ChildRemovedArgs, expected));
}
示例11: TestSubscribeAndUnsubscribe
public void TestSubscribeAndUnsubscribe()
{
DomNode root = new DomNode(RootType);
Validator validator = root.As<Validator>();
DomNode child = new DomNode(ChildType);
DomNode grandchild = new DomNode(ChildType);
child.SetChild(ChildInfo, grandchild);
root.SetChild(ChildInfo, child);
ValidationContext context = grandchild.As<ValidationContext>();
context.RaiseBeginning();
Assert.True(validator.IsValidating);
Assert.AreSame(validator.Sender, context);
Assert.AreSame(validator.E, EventArgs.Empty);
context.RaiseEnded();
root.SetChild(ChildInfo, null);
context.RaiseBeginning();
Assert.False(validator.IsValidating);
}
示例12: PopulateDomNode
/// <summary>
/// Populates DomNode with data from stream data</summary>
/// <param name="stream">Stream to read data into</param>
/// <param name="node">Node to populate</param>
/// <param name="resolvedUri">URI representing object file</param>
public static void PopulateDomNode(Stream stream, ref DomNode node, Uri resolvedUri)
{
// Parse .obj file
var obj = new ObjFile();
obj.Read(stream, resolvedUri);
if (node == null)
node = new DomNode(Schema.nodeType.Type);
// Populate mesh
var mesh = new DomNode(Schema.meshType.Type);
mesh.SetAttribute(Schema.meshType.nameAttribute, Path.GetFileName(resolvedUri.LocalPath));
var vertexArray = new DomNode(Schema.meshType_vertexArray.Type);
// Populate primitive data
foreach (Group group in obj.m_groups.Values)
foreach (FaceSet face in group.FaceSets.Values)
{
var primitive = new DomNode(Schema.vertexArray_primitives.Type);
primitive.SetAttribute(Schema.vertexArray_primitives.indicesAttribute, face.Indices.ToArray());
primitive.SetAttribute(Schema.vertexArray_primitives.sizesAttribute, face.Sizes.ToArray());
primitive.SetAttribute(Schema.vertexArray_primitives.typeAttribute, "POLYGONS");
// Populate shader
MaterialDef material;
obj.m_mtl.Materials.TryGetValue(face.MaterialName, out material);
if (material != null)
{
string texture = null;
if (material.TextureName != null)
texture = new Uri(resolvedUri, material.TextureName).AbsolutePath;
var shader = new DomNode(Schema.shaderType.Type);
shader.SetAttribute(Schema.shaderType.nameAttribute, material.Name);
shader.SetAttribute(Schema.shaderType.ambientAttribute, material.Ambient);
shader.SetAttribute(Schema.shaderType.diffuseAttribute, material.Diffuse);
shader.SetAttribute(Schema.shaderType.shininessAttribute, material.Shininess);
shader.SetAttribute(Schema.shaderType.specularAttribute, material.Specular);
shader.SetAttribute(Schema.shaderType.textureAttribute, texture);
primitive.SetChild(Schema.vertexArray_primitives.shaderChild, shader);
}
// Note: Bindings must be in the order: normal, map1, position
DomNode binding;
if (face.HasNormals)
{
binding = new DomNode(Schema.primitives_binding.Type);
binding.SetAttribute(Schema.primitives_binding.sourceAttribute, "normal");
primitive.GetChildList(Schema.vertexArray_primitives.bindingChild).Add(binding);
}
if (face.HasTexCoords)
{
binding = new DomNode(Schema.primitives_binding.Type);
binding.SetAttribute(Schema.primitives_binding.sourceAttribute, "map1");
primitive.GetChildList(Schema.vertexArray_primitives.bindingChild).Add(binding);
}
binding = new DomNode(Schema.primitives_binding.Type);
binding.SetAttribute(Schema.primitives_binding.sourceAttribute, "position");
primitive.GetChildList(Schema.vertexArray_primitives.bindingChild).Add(binding);
vertexArray.GetChildList(Schema.meshType_vertexArray.primitivesChild).Add(primitive);
}
// Populate array data
DomNode array;
if (obj.m_normals.Count > 0)
{
array = new DomNode(Schema.vertexArray_array.Type);
array.SetAttribute(Schema.vertexArray_array.Attribute, obj.m_normals.ToArray());
array.SetAttribute(Schema.vertexArray_array.countAttribute, obj.m_normals.Count / 3);
array.SetAttribute(Schema.vertexArray_array.nameAttribute, "normal");
array.SetAttribute(Schema.vertexArray_array.strideAttribute, 3);
vertexArray.GetChildList(Schema.meshType_vertexArray.arrayChild).Add(array);
}
if (obj.m_texcoords.Count > 0)
{
array = new DomNode(Schema.vertexArray_array.Type);
array.SetAttribute(Schema.vertexArray_array.Attribute, obj.m_texcoords.ToArray());
array.SetAttribute(Schema.vertexArray_array.countAttribute, obj.m_texcoords.Count / 2);
array.SetAttribute(Schema.vertexArray_array.nameAttribute, "map1");
array.SetAttribute(Schema.vertexArray_array.strideAttribute, 2);
vertexArray.GetChildList(Schema.meshType_vertexArray.arrayChild).Add(array);
}
array = new DomNode(Schema.vertexArray_array.Type);
array.SetAttribute(Schema.vertexArray_array.Attribute, obj.m_positions.ToArray());
array.SetAttribute(Schema.vertexArray_array.countAttribute, obj.m_positions.Count / 3);
//.........这里部分代码省略.........
示例13: CreatePrototype
private DomNode CreatePrototype(IEnumerable<IGameObject> gobs)
{
DomNode[] originals = new DomNode[1];
List<IGameObject> copyList = new List<IGameObject>();
AABB bound = new AABB();
foreach (IGameObject gameObject in SelectedGobs)
{
IBoundable boundable = gameObject.As<IBoundable>();
bound.Extend(boundable.BoundingBox);
Matrix4F world = TransformUtils.ComputeWorldTransform(gameObject);
originals[0] = gameObject.As<DomNode>();
DomNode[] copies = DomNode.Copy(originals);
IGameObject copy = copies[0].As<IGameObject>();
TransformUtils.SetTransform(copy, world);
copyList.Add(copy);
}
DomNode gobchild = null;
if (copyList.Count > 1)
{// create group
IGame game = m_contextRegistry.GetActiveContext<IGame>();
IGameObjectGroup gobgroup = game.CreateGameObjectGroup();
gobgroup.Translation = bound.Center;
gobgroup.UpdateTransform();
Matrix4F worldInv = new Matrix4F();
worldInv.Invert(gobgroup.Transform);
foreach (IGameObject gob in copyList)
{
Vec3F translate = gob.Translation;
worldInv.Transform(ref translate);
gob.Translation = translate;
gob.UpdateTransform();
gobgroup.GameObjects.Add(gob);
}
gobchild = gobgroup.As<DomNode>();
}
else
{
gobchild = copyList[0].As<DomNode>();
}
gobchild.InitializeExtensions();
gobchild.As<IGameObject>().Translation = new Vec3F(0, 0, 0);
DomNode prototype = null;
if (gobchild != null)
{
prototype = new DomNode(Schema.prototypeType.Type, Schema.prototypeRootElement);
prototype.SetChild(Schema.prototypeType.gameObjectChild, gobchild);
}
return prototype;
}
示例14: GetOrCreateMissingTemplateNode
private DomNode GetOrCreateMissingTemplateNode(string guid)
{
if (m_missingTemplates == null)
m_missingTemplates = new Dictionary<string, DomNode>();
DomNode templateNode;
if (m_missingTemplates.TryGetValue(guid, out templateNode))
return templateNode;
templateNode = new DomNode(Schema.missingTemplateType.Type);
templateNode.SetAttribute(Schema.missingTemplateType.guidAttribute, guid);
var moduleChild = new DomNode(Schema.missingModuleType.Type);
templateNode.SetChild(Schema.missingTemplateType.moduleChild, moduleChild);
return templateNode;
}
示例15: Test
//.........这里部分代码省略.........
node3.GetChildList(elem3).Add(elem3Child2);
node3.GetChildList(elem3).Add(elem3Child3);
IList<DomNode> node3Children = node3.GetChildList(elem3);
Assert.IsTrue((int)node3Children[0].GetAttribute(elem3ValueAttributeInfo) == 1);
Assert.IsTrue((int)node3Children[1].GetAttribute(elem3ValueAttributeInfo) == 1);
Assert.IsTrue((int)node3Children[2].GetAttribute(elem3ValueAttributeInfo) == 1);
// Update on 8/16/2011. DomXmlReader would not be able to handle a sequence of elements
// of a simple type like this. When reading, each subsequent element's value would be
// used to set the attribute on the DomNode, overwriting the previous one. So, since
// this behavior of converting more than one element of a simple type into an attribute
// array was broken, I want to change this unit test that I wrote and make sequences of
// elements of simple types into a sequence of DomNode children with a value attribute.
// (A value attribute means an attribute whose name is "".) --Ron
//ChildInfo elem3 = complexType3.GetChildInfo("elem3");
//Assert.IsTrue(elem3 == null); //because a sequence of simple types becomes an attribute
//attr3 = complexType3.GetAttributeInfo("elem3");
//Assert.IsTrue(attr3 != null); //because a sequence of simple types becomes an attribute
//DomNode node3 = new DomNode(complexType3);
//object attr3Obj = node3.GetAttribute(attr3);
//Assert.IsTrue(
// attr3Obj is int &&
// (int)attr3Obj == 0); //the default integer
//node3.SetAttribute(attr3, 1);
//attr3Obj = node3.GetAttribute(attr3);
//Assert.IsTrue(
// attr3Obj is int &&
// (int)attr3Obj == 1);
//node3.SetAttribute(attr3, new int[] { 1, 2, 3 });
//attr3Obj = node3.GetAttribute(attr3);
//Assert.IsTrue(
// attr3Obj is int[] &&
// ((int[])attr3Obj)[2]==3);
DomNodeType complexType4 = loader.GetNodeType("test:complexType4");
Assert.IsTrue(complexType4 != null);
Assert.IsTrue(!complexType4.IsAbstract);
attr1 = complexType4.GetAttributeInfo("attr1");
Assert.IsTrue(attr1 != null);
elem1 = complexType4.GetChildInfo("elem1");
Assert.IsTrue(elem1 != null);
Assert.IsTrue(elem1.Type == complexType3);
Assert.IsTrue(MinMaxCheck(elem1, 1, 1));
DomNodeType complexType5 = loader.GetNodeType("test:complexType5");
Assert.IsTrue(complexType5 != null);
Assert.IsTrue(!complexType5.IsAbstract);
elem1 = complexType5.GetChildInfo("elem1");
Assert.IsTrue(elem1 != null);
Assert.IsTrue(elem1.Type == abstractType);
Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));
DomNode node5 = new DomNode(complexType5);
elem2 = complexType5.GetChildInfo("elem2");
DomNode node2 = new DomNode(complexType2);
node5.SetChild(elem2, node2);
node5.SetChild(elem2, null);
node3 = new DomNode(complexType3);
elem3 = complexType5.GetChildInfo("elem3");
node5.SetChild(elem3, node3);
//The following should violate xs:choice, but we don't fully support this checking yet.
//ExceptionTester.CheckThrow<InvalidOperationException>(delegate { node5.AddChild(elem2, node2); });
DomNodeType complexType6 = loader.GetNodeType("test:complexType6");
Assert.IsTrue(complexType6 != null);
Assert.IsTrue(!complexType6.IsAbstract);
elem1 = complexType6.GetChildInfo("elem1");
Assert.IsTrue(elem1 != null);
Assert.IsTrue(elem1.Type == abstractType);
Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));
elem2 = complexType6.GetChildInfo("elem2");
Assert.IsTrue(elem2 != null);
Assert.IsTrue(elem2.Type == complexType2);
Assert.IsTrue(MinMaxCheck(elem2, 1, Int32.MaxValue));
//DomNodeType complexType7 = loader.GetNodeType("test:complexType7");
//Assert.IsTrue(complexType7 != null);
//Assert.IsTrue(!complexType7.IsAbstract);
//AttributeInfo attrSimpleSequence = complexType7.GetAttributeInfo("elemSimpleSequence");
//Assert.IsTrue(attrSimpleSequence == null); //because a sequence of simple types becomes a sequence of child DomNodes
//ChildInfo elemSimpleSequence = complexType7.GetChildInfo("elemSimpleSequence");
//Assert.IsTrue(elemSimpleSequence != null); //because a sequence of simple types becomes a sequence of child DomNodes
//DomNode node7 = new DomNode(complexType7);
//object attrObj7 = node7.GetAttribute(attrSimpleSequence);
//Assert.IsTrue(
// attrObj7 is float[] &&
// ((float[])attrObj7)[0] == 0 &&
// ((float[])attrObj7)[1] == 0 &&
// ((float[])attrObj7)[2] == 0); //the default vector
//float[][] newSequence =
//{
// new float[] {1, 2, 3},
// new float[] {4, 5, 6},
// new float[] {7, 8, 9}
//};
//node7.SetAttribute(attrSimpleSequence, newSequence);
//attrObj7 = node7.GetAttribute(attrSimpleSequence);
//Assert.IsTrue(ArraysEqual(attrObj7, newSequence));
}