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


C# DomNode.SetAttribute方法代码示例

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


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

示例1: 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

示例2: 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

示例3: CreateClub

 private static DomNode CreateClub(bool hasSpikes, int damage, float weight)
 {
     var club = new DomNode(Schema.clubType.Type);
     club.SetAttribute(Schema.clubType.spikesAttribute, hasSpikes);
     club.SetAttribute(Schema.clubType.DamageAttribute, damage);
     club.SetAttribute(Schema.clubType.wieghtAttribute, weight);
     return club;
 }
开发者ID:vincenthamm,项目名称:ATF,代码行数:8,代码来源:Editor.cs

示例4: CreateArmor

 private static DomNode CreateArmor(string name, int defense, int price)
 {
     var armor = new DomNode(Schema.armorType.Type);
     armor.SetAttribute(Schema.armorType.nameAttribute, name);
     armor.SetAttribute(Schema.armorType.defenseAttribute, defense);
     armor.SetAttribute(Schema.armorType.priceAttribute, price);
     return armor;
 }
开发者ID:vincenthamm,项目名称:ATF,代码行数:8,代码来源:Editor.cs

示例5: DomNode

        /// <summary>
        /// Converts the palette item into an object that can be inserted into an
        /// IInstancingContext</summary>
        /// <param name="item">Item to convert</param>
        /// <returns>Object that can be inserted into an IInstancingContext</returns>
        object IPaletteClient.Convert(object item)
        {
            DomNodeType nodeType = (DomNodeType)item;
            DomNode node = new DomNode(nodeType);

            NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>();
            if (paletteItem != null)
            {
                if (nodeType.IdAttribute != null)
                    node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing

                if (nodeType == Schema.stateType.Type)
                    node.SetAttribute(Schema.stateType.labelAttribute, paletteItem.Name);   // user visible name for state
            }
            return node;
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:21,代码来源:PaletteClient.cs

示例6: DomNode

        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
                {
                    // create root node.
                    var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
                    rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game");

                    // create Orc game object and add it to rootNode.
                    var orc = CreateOrc();
                    rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc);

                    // add a child Orc.
                    var orcChildList = orc.GetChildList(Schema.orcType.orcChild);
                    orcChildList.Add(CreateOrc("Child Orc1"));

                    rootNode.InitializeExtensions();

                    var edContext = rootNode.Cast<GameEditingContext>();
                    edContext.Set(orc);

                    // set active context and select orc object.
                    m_contextRegistry.ActiveContext = rootNode;
                    
                };
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:28,代码来源:Editor.cs

示例7: CreateOrc

        /// <summary>
        /// Helper method to create instance of orcType.</summary>
        private static DomNode CreateOrc(string name = "Orc")
        {
            var orc = new DomNode(Schema.orcType.Type);
            orc.SetAttribute(Schema.orcType.nameAttribute, name);
            orc.SetAttribute(Schema.orcType.TextureRevDateAttribute, DateTime.Now);
            orc.SetAttribute(Schema.orcType.resourceFolderAttribute,System.Windows.Forms.Application.StartupPath);
            orc.SetAttribute(Schema.orcType.skinColorAttribute, System.Drawing.Color.DarkGray.ToArgb());
            orc.SetAttribute(Schema.orcType.healthAttribute, 80);
            var armorList = orc.GetChildList(Schema.orcType.armorChild);

            armorList.Add(CreateArmor("Iron breast plate",20,300));

            var clubList = orc.GetChildList(Schema.orcType.clubChild);
            clubList.Add(CreateClub(true, 20, 30));

            return orc;
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:19,代码来源:Editor.cs

示例8: Create

        public static TerrainGob Create(string name, string hmPath, float cellSize)
        {            
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException(name);

            if (!File.Exists(hmPath))
                throw new ArgumentException(hmPath + " does not exist");
            
            Uri ur = new Uri(hmPath);
            DomNode terrainNode = new DomNode(Schema.terrainGobType.Type);            
            terrainNode.SetAttribute(Schema.terrainGobType.cellSizeAttribute, cellSize);
            terrainNode.SetAttribute(Schema.terrainGobType.heightMapAttribute, ur);
            terrainNode.InitializeExtensions();
            TerrainGob terrain = terrainNode.As<TerrainGob>();
            terrain.Name = name;
            return terrain;
        }
开发者ID:arsaccol,项目名称:LevelEditor,代码行数:17,代码来源:TerrainGob.cs

示例9: OnNodeSet

 /// <summary>
 /// Performs initialization when the adapter is connected to the diagram annotation's DomNode,
 /// creating child DomNode for transform and setting its scale.</summary>
 protected override void OnNodeSet()
 {
     DomNode transform = DomNode.GetChild(UISchema.UIControlType.TransformChild);
     if (transform == null)
     {
         transform = new DomNode(UISchema.UITransformType.Type);
         transform.SetAttribute(UISchema.UITransformType.ScaleAttribute, new float[] { 1.0f, 1.0f, 1.0f });
         DomNode.SetChild(UISchema.UIControlType.TransformChild, transform);
     }
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:13,代码来源:UIControl.cs

示例10: Convert

 /// <summary>
 /// Converts the palette item into an object that can be inserted into an
 /// IInstancingContext</summary>
 /// <param name="item">Item to convert</param>
 /// <returns>Object that can be inserted into an IInstancingContext</returns>
 public object Convert(object item)
 {
     DomNodeType nodeType = (DomNodeType)item;
     DomNode node = new DomNode(nodeType);
     NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>();
     if (paletteItem != null)
     {
         node.SetAttribute(nodeType.IdAttribute, paletteItem.Name);
     }            
     return node;
 }
开发者ID:sbambach,项目名称:ATF,代码行数:16,代码来源:PaletteClient.cs

示例11: ReadAttribute

        /// <summary>
        /// Converts the give string to attribute value and set it to given node
        /// using attributeInfo.         
        /// </summary>
        /// <param name="node">DomNode </param>
        /// <param name="attributeInfo">attributeInfo to set</param>
        /// <param name="valueString">The string representation of the attribute value</param>
        protected override void ReadAttribute(DomNode node, AttributeInfo attributeInfo, string valueString)
        {
            if (IsReferenceAttribute(attributeInfo))
            {
                // save reference so it can be resolved after all nodes have been read
                NodeReferences.Add(new XmlNodeReference(node, attributeInfo, valueString));
            }
            else if (!string.IsNullOrEmpty(valueString))
            {
                object value = attributeInfo.Type.Convert(valueString);

                if (value is Uri)
                {
                    //todo reference to objects in other documents must be made absolute using
                    //this Uri instead of resourceRoot.

                    // then convert it to absolute.
                    Uri ur = (Uri)value;
                    if (!ur.IsAbsoluteUri)
                    {
                        // todo use schema annotation to decide what to use 
                        // for converting relative uri to absolute.
                        if (node.Type == Schema.gameReferenceType.Type
                            || node.Type == Schema.gameObjectReferenceType.Type)
                        {
                            string urStr = ur.ToString();
                            int fragIndex = urStr.LastIndexOf('#');
                            if (fragIndex == -1)
                            {
                                value = new Uri(Uri, ur);
                            }
                            else
                            {
                                string frag = urStr.Substring(fragIndex);
                                string path = urStr.Substring(0, fragIndex);
                                Uri absUri = new Uri(Uri, path);
                                value = new Uri(absUri + frag);
                            }

                        }
                        else
                        {
                            value = new Uri(m_resourceRoot, ur);
                        }

                    }
                }
                node.SetAttribute(attributeInfo, value);
            }
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:57,代码来源:CustomDomXmlReader.cs

示例12: TestCopy_SingleNode

        public void TestCopy_SingleNode()
        {
            DomNodeType type = new DomNodeType("type");
            AttributeInfo info = GetStringAttribute("string");
            type.Define(info);
            DomNode test = new DomNode(type);
            test.SetAttribute(info, "foo");

            DomNode[] result = DomNode.Copy(new DomNode[] { test });
            Assert.True(Equals(result[0], test));

            DomNode singleResult = DomNode.Copy(test);
            Assert.True(Equals(singleResult, test));
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:14,代码来源:TestDomNode.cs

示例13: TestAttributeChangedEvents

        public void TestAttributeChangedEvents()
        {
            DomNodeType type = new DomNodeType("type");
            AttributeInfo stringTypeInfo = GetStringAttribute("string");
            AttributeInfo intTypeInfo = GetIntAttribute("int");
            type.Define(stringTypeInfo);
            type.Define(intTypeInfo);
            DomNode test = new DomNode(type);
            test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging);
            test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged);
            AttributeEventArgs expected;

            // test for no value change if setting to the default value and attribute is already the default
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(stringTypeInfo, stringTypeInfo.DefaultValue);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);
            test.SetAttribute(intTypeInfo, intTypeInfo.DefaultValue);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);

            // test for value change, string type
            test = new DomNode(type);
            test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging);
            test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged);
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            object oldValue = test.GetAttribute(stringTypeInfo);
            test.SetAttribute(stringTypeInfo, "foo");
            expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foo");
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            oldValue = test.GetAttribute(stringTypeInfo);
            test.SetAttribute(stringTypeInfo, "foobar");
            expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foobar");
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            // test for value change, int type
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            oldValue = test.GetAttribute(intTypeInfo);
            test.SetAttribute(intTypeInfo, 5);
            expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 5);
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            oldValue = test.GetAttribute(intTypeInfo);
            test.SetAttribute(intTypeInfo, 7);
            expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 7);
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            // test for no value change
            test.SetAttribute(stringTypeInfo, "foo");
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(stringTypeInfo, "foo");
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);

            test.SetAttribute(intTypeInfo, 9);
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(intTypeInfo, 9);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:70,代码来源:TestDomNode.cs

示例14: TestGetId

        public void TestGetId()
        {
            DomNodeType testId = new DomNodeType("test");
            AttributeInfo info = GetStringAttribute("string");
            testId.Define(info);
            testId.SetIdAttribute(info.Name);
            DomNode test = new DomNode(testId);
            Assert.Null(test.GetId());

            test.SetAttribute(info, "foo");
            Assert.AreEqual(test.GetId(), "foo");
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:12,代码来源:TestDomNode.cs

示例15: TestSetAttribute

        public void TestSetAttribute()
        {
            DomNodeType type = new DomNodeType("child");
            AttributeInfo info = GetIntAttribute("int");
            type.Define(info);
            DomNode test = new DomNode(type);

            Assert.False(test.IsAttributeSet(info));
            test.SetAttribute(info, 2);
            Assert.AreEqual(test.GetAttribute(info), 2);
            Assert.AreEqual(test.GetLocalAttribute(info), 2);
            Assert.True(test.IsAttributeSet(info));

            test.SetAttribute(info, null);
            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:18,代码来源:TestDomNode.cs


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