当前位置: 首页>>代码示例>>C#>>正文


C# DomNode类代码示例

本文整理汇总了C#中DomNode的典型用法代码示例。如果您正苦于以下问题:C# DomNode类的具体用法?C# DomNode怎么用?C# DomNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DomNode类属于命名空间,在下文中一共展示了DomNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Write

        /// <summary>
        /// Writes the node tree to a stream</summary>
        /// <param name="root">Node tree to write</param>
        /// <param name="stream">Write stream</param>
        /// <param name="uri">URI of stream</param>
        public virtual void Write(DomNode root, Stream stream, Uri uri)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = "\t";
            settings.NewLineHandling = NewLineHandling.Replace;
            settings.NewLineChars = "\r\n";

            XmlWriter writer = null;
            try
            {
                m_uri = uri;

                writer = XmlWriter.Create(stream, settings);
                writer.WriteStartDocument();

                m_root = root;

                WriteElement(root, writer);

                writer.WriteEndDocument();
            }
            finally
            {
                if (writer != null)
                    ((IDisposable)writer).Dispose();

                m_uri = null;
                m_root = null;
            }
        }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:36,代码来源:XmlPersister.cs

示例2: TestDefaultValue

        public void TestDefaultValue()
        {
            AttributeType type = new AttributeType("test", typeof(string));
            AttributeInfo test = new AttributeInfo("test", type);
            test.DefaultValue = "foo";
            Assert.AreEqual(test.DefaultValue, "foo");
            test.DefaultValue = null;
            Assert.AreEqual(test.DefaultValue, type.GetDefault());
            Assert.Throws<InvalidOperationException>(delegate { test.DefaultValue = 1; });

            AttributeType length2Type = new AttributeType("length2Type", typeof(int[]), 2);
            AttributeInfo length2Info = new AttributeInfo("length2", length2Type);
            Assert.AreEqual(length2Info.DefaultValue, length2Type.GetDefault());
            Assert.AreEqual(length2Info.DefaultValue, new int[] { default(int), default(int) });
            DomNodeType nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length2Info);
            DomNode node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length2Info), length2Info.DefaultValue);
            node.SetAttribute(length2Info, new int[] { 1, 2 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1, 2 });
            node.SetAttribute(length2Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1 });

            AttributeType length1Type = new AttributeType("length1Type", typeof(int[]), 1);
            AttributeInfo length1Info = new AttributeInfo("length1", length1Type);
            Assert.AreEqual(length1Info.DefaultValue, length1Type.GetDefault());
            Assert.AreEqual(length1Info.DefaultValue, new int[] { default(int) });
            nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length1Info);
            node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length1Info), length1Info.DefaultValue);
            node.SetAttribute(length1Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length1Info), new int[] { 1 });
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:34,代码来源:TestAttributeInfo.cs

示例3: TestValidate

        public void TestValidate()
        {
            DomNodeType childType = new DomNodeType("child");
            DomNodeType parentType = new DomNodeType("parent");
            ChildInfo childInfo = new ChildInfo("child", childType, true);
            parentType.Define(childInfo);
            DomNode parent = new DomNode(parentType);
            IList<DomNode> childList = parent.GetChildList(childInfo);
            DomNode child1 = new DomNode(childType);
            DomNode child2 = new DomNode(childType);
            DomNode child3 = new DomNode(childType);

            ChildCountRule test = new ChildCountRule(1, 2);
            
            // 0 children. Not valid.
            Assert.False(test.Validate(parent, null, childInfo));

            // 1 child. Valid.
            childList.Add(child1);
            Assert.True(test.Validate(parent, null, childInfo));
            
            // 2 children. Valid.
            childList.Add(child2);
            Assert.True(test.Validate(parent, null, childInfo));

            // 3 children. Not valid.
            childList.Add(child3);
            Assert.False(test.Validate(parent, null, childInfo));

            // 0 children. Not valid.
            childList.Clear();
            Assert.False(test.Validate(parent, null, childInfo));
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:33,代码来源:TestChildCountRule.cs

示例4: DomNode

        /// <summary>
        /// Does a command</summary>
        /// <param name="commandTag">Command</param>
        void ICommandClient.DoCommand(object commandTag)
        {
            if (CommandTag.AddLayerFolder.Equals(commandTag))
            {
                LayerFolder newLayer = new DomNode(LayerFolderType).As<LayerFolder>();
                newLayer.Name = "New Layer".Localize();

                IList<LayerFolder> layerList = null;
                object target = m_targetRef.Target;
                if (target != null)
                {
                    LayerFolder parentLayer = target.As<LayerFolder>();
                    if (parentLayer != null)
                        layerList = parentLayer.Folders;
                    else
                    {
                        LayeringContext layeringContext = target.As<LayeringContext>();
                        if (layeringContext != null)
                            layerList = layeringContext.Layers;
                    }
                }

                if (layerList != null)
                {
                    ILayeringContext layeringContext = m_contextRegistry.GetMostRecentContext<ILayeringContext>();
                    ITransactionContext transactionContext = layeringContext.As<ITransactionContext>();
                    transactionContext.DoTransaction(() => layerList.Add(newLayer), "Add Layer".Localize());
                }
            }
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:33,代码来源:LayeringCommands.cs

示例5: TestBaseType

        public void TestBaseType()
        {
            DomNodeType test = new DomNodeType("test");
            Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
            DomNodeType baseType = new DomNodeType("base");
            test.BaseType = baseType;
            Assert.AreEqual(test.BaseType, baseType);

            DomNode node = new DomNode(test);
            // base type is now frozen
            Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });

            test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable<AttributeInfo>.Instance,
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
            test.BaseType = baseType;
            Assert.AreEqual(test.BaseType, baseType);

            node = new DomNode(test);
            Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:26,代码来源:TestDomNodeType.cs

示例6: AddNewLayer

        private void AddNewLayer()
        {
            object lastHit = m_layerLister.LastHit;
            ILayer newLayer = new DomNode(Schema.layerType.Type).As<ILayer>();
            newLayer.Name = "New Layer".Localize();

            IList<ILayer> layerList = null;
            var layer = lastHit.As<ILayer>();
            if (layer != null)
            {
                layerList = layer.Layers;
            }
            else
            {
                LayeringContext layeringContext = m_layerLister.TreeView.As<LayeringContext>();
                    if (layeringContext != null)
                        layerList = layeringContext.Layers;
            }
            if (layerList != null)
            {
                var transactionContext = m_layerLister.TreeView.As<ITransactionContext>();
                transactionContext.DoTransaction(
                    delegate
                    {
                        layerList.Add(newLayer);
                    },
                    m_addLayer.Text);
            }
        }
开发者ID:ldh9451,项目名称:XLE,代码行数:29,代码来源:LayeringCommands.cs

示例7: CreateGameUsingDomNode

        /// <summary>
        /// Creates game using raw DomNode</summary>        
        private static DomNode CreateGameUsingDomNode()
        {                                     
            // create Dom node of the root type defined by the schema
            DomNode game = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);
            game.SetAttribute(GameSchema.gameType.nameAttribute, "Ogre Adventure II");
            IList<DomNode> childList = game.GetChildList(GameSchema.gameType.gameObjectChild);

            // Add an ogre
            DomNode ogre = new DomNode(GameSchema.ogreType.Type);
            ogre.SetAttribute(GameSchema.ogreType.nameAttribute, "Bill");
            ogre.SetAttribute(GameSchema.ogreType.sizeAttribute, 12);
            ogre.SetAttribute(GameSchema.ogreType.strengthAttribute, 100);
            childList.Add(ogre);


            // Add a dwarf
            DomNode dwarf = new DomNode(GameSchema.dwarfType.Type);
            dwarf.SetAttribute(GameSchema.dwarfType.nameAttribute, "Sally");
            dwarf.SetAttribute(GameSchema.dwarfType.ageAttribute, 32);
            dwarf.SetAttribute(GameSchema.dwarfType.experienceAttribute, 55);
            childList.Add(dwarf);

            // Add a tree
            DomNode tree = new DomNode(GameSchema.treeType.Type);
            tree.SetAttribute(GameSchema.treeType.nameAttribute, "Mr. Oak");
            childList.Add(tree);

            return game;           
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:31,代码来源:Program.cs

示例8: CreateGameUsingDomNodeAdapter

        /// <summary>
        /// Creates game using DomNode adapter</summary>        
        private static DomNode CreateGameUsingDomNodeAdapter()
        {
            // create game.
            DomNode root = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);
            Game game = root.As<Game>();
            game.Name = "Ogre Adventure II";

            // Add an ogre
            DomNode ogreNode = new DomNode(GameSchema.ogreType.Type);
            Ogre orge = ogreNode.As<Ogre>();
            orge.Name = "Bill";
            orge.Size = 12;
            orge.Strength = 100;
            game.GameObjects.Add(orge);

            // Add a dwarf
            DomNode dwarfNode = new DomNode(GameSchema.dwarfType.Type);
            Dwarf dwarf = dwarfNode.As<Dwarf>();
            dwarf.Name = "Sally";
            dwarf.Age = 32;
            dwarf.Experience = 55;
            game.GameObjects.Add(dwarf);

            // Add a tree
            DomNode treeNode = new DomNode(GameSchema.treeType.Type);
            GameObject tree = treeNode.As<GameObject>();
            tree.Name = "Mr. Oak";
            game.GameObjects.Add(tree);

            return game.DomNode;
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:33,代码来源:Program.cs

示例9: PrimInput

        /// <summary>
        /// Constructor</summary>
        /// <param name="input">DomNode</param>
        /// <param name="mesh">Mesh</param>
        public PrimInput(DomNode input, Mesh mesh)
        {
            AttributeInfo srcAttrib = null;
            AttributeInfo offsetAttrib = null;
            AttributeInfo semantiAttrib = null;

            if (input.Type == Schema.InputLocalOffset.Type)
            {
                srcAttrib = Schema.InputLocalOffset.sourceAttribute;
                offsetAttrib = Schema.InputLocalOffset.offsetAttribute;
                semantiAttrib = Schema.InputLocalOffset.semanticAttribute;                
            }
            else if (input.Type == Schema.InputLocal.Type)
            {
                srcAttrib = Schema.InputLocal.sourceAttribute;                
                semantiAttrib = Schema.InputLocal.semanticAttribute;                
            }
            else
            {
                throw new ArgumentException(input.Type.ToString() + " is not supported");
            }


            // find the source for this input.
            string srcId = (string)input.GetAttribute(srcAttrib);
            srcId = srcId.Replace("#", "").Trim();

            foreach (Source src in mesh.Sources)
            {
                if (src.Id == srcId)
                {
                    m_source = src;
                    break;
                }
            }

            if (offsetAttrib != null)
                m_offset = Convert.ToInt32(input.GetAttribute(offsetAttrib));
            else
                m_offset = -1;

            m_semantic = (string)input.GetAttribute(semantiAttrib);

            switch (m_semantic)
            {
                case "POSITION":
                    m_atgiName = "position";
                    break;
                case "NORMAL":
                    m_atgiName = "normal";
                    break;
                case "TEXCOORD":
                    m_atgiName = "map1";
                    break;
                case "COLOR":
                    m_atgiName = "color";
                    break;
            }      

        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:64,代码来源:Input.cs

示例10: RemoveNode

        /// <summary>
        /// Performs custom actions for a node that has been removed from the DOM subtree</summary>
        /// <param name="node">Removed node</param>
        protected override void RemoveNode(DomNode node)
        {
            foreach (DomNode dependency in GetDependencies(node))
                m_dependencySystem.RemoveDependency(node, dependency);

            base.RemoveNode(node);
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:10,代码来源:DependencyValidator.cs

示例11: Traverse

        public void Traverse(DomNode root)
        {
            DomNode node = root;
            int depth = 0;

            while (node != null) {
                visitor.Head(node, depth);
                if (node.ChildNodes.Count > 0) {
                    node = node.ChildNode(0);
                    depth++;
                }

                else {
                    while (node.NextSibling == null && depth > 0) {
                        visitor.Tail(node, depth);
                        node = node.ParentNode;
                        depth--;
                    }
                    visitor.Tail(node, depth);
                    if (node == root)
                        break;
                    node = node.NextSibling;
                }
            }
        }
开发者ID:Carbonfrost,项目名称:ff-web-dom,代码行数:25,代码来源:NodeTraversor.cs

示例12: New

 /// <summary>
 /// Creates a new UIRef adapter and underlying DomNode</summary>
 /// <param name="uiObj">UIObject being referenced</param>
 /// <returns>New UIRef adapter</returns>
 public static UIRef New(UIObject uiObj)
 {
     DomNode node = new DomNode(UISchema.UIRefType.Type);
     UIRef uiRef = node.As<UIRef>();
     uiRef.UIObject = uiObj;
     return uiRef;
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:11,代码来源:UIRef.cs

示例13: GetNodeTitle

		string GetNodeTitle(DomNode node)
		{
			StringBuilder b = new StringBuilder();
			b.Append(DecodeRole(node.Role, node.Parent != null ? node.Parent.GetType() : null));
			b.Append(": ");
			b.Append(node.GetType().Name);
			bool hasProperties = false;
			foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
				if (p.Name == "NodeType" || p.Name == "IsNull")
					continue;
				if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) {
					if (!hasProperties) {
						hasProperties = true;
						b.Append(" (");
					} else {
						b.Append(", ");
					}
					b.Append(p.Name);
					b.Append(" = ");
					try {
						object val = p.GetValue(node, null);
						b.Append(val != null ? val.ToString() : "**null**");
					} catch (TargetInvocationException ex) {
						b.Append("**" + ex.InnerException.GetType().Name + "**");
					}
				}
			}
			if (hasProperties)
				b.Append(")");
			return b.ToString();
		}
开发者ID:infodoc,项目名称:NRefactory,代码行数:31,代码来源:MainForm.cs

示例14: TestBaseType

        public void TestBaseType()
        {
            DomNodeType test = new DomNodeType("test");
            Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
            DomNodeType baseType = new DomNodeType("base");
            test.BaseType = baseType;
            Assert.AreEqual(test.BaseType, baseType);

            #pragma warning disable 219 //Disable the unused local variable warning. We need the side-effect of creating the DomNode.
            DomNode node = new DomNode(test);
            #pragma warning restore 219
            // base type is now frozen
            Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });

            test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable<AttributeInfo>.Instance,
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
            test.BaseType = baseType;
            Assert.AreEqual(test.BaseType, baseType);

            // ReSharper disable once RedundantAssignment
            node = new DomNode(test);
            Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });
        }
开发者ID:sbambach,项目名称:ATF,代码行数:29,代码来源:TestDomNodeType.cs

示例15: CreateExpression

 public Expression CreateExpression()
 {
     Expression exp = new DomNode(Schema.expressionType.Type).Cast<Expression>();
     exp.Id = "Expression";
     exp.Label = "Expression".Localize();
     return exp;
 }
开发者ID:sbambach,项目名称:ATF,代码行数:7,代码来源:ExpressionManager.cs


注:本文中的DomNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。