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


C# DomNode.GetAttribute方法代码示例

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


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

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

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

 protected override void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // Filter out external template file references that should not be in-lined
     if (node.Is<TemplateFolder>())
     {
         var pathUri = node.GetAttribute(Schema.templateFolderType.referenceFileAttribute) as Uri;
         if (pathUri != null)
             return;
     }
     base.WriteChildElementsRecursive(node, writer);
 }
开发者ID:GeertVL,项目名称:ATF,代码行数:11,代码来源:CircuitWriter.cs

示例4: GetSphere

 /// <summary>
 /// Gets the DomNode attribute as a Sphere3F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>DomNode attribute as a Sphere3F</returns>
 public static Sphere3F GetSphere(DomNode domNode, AttributeInfo attribute)
 {
     Sphere3F s = new Sphere3F();
     float[] value = domNode.GetAttribute(attribute) as float[];
     if (value != null)
     {
         s.Center = new Vec3F(value[0], value[1], value[2]);
         s.Radius = value[3];
     }
     return s;
 }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:16,代码来源:DomNodeUtil.cs

示例5: Convert

		protected override string Convert(DomNode node, AttributeInfo attributeInfo)
		{
			object value = node.GetAttribute(attributeInfo);
			if (attributeInfo.Type.Type == AttributeTypes.Reference && attributeInfo.Name == "guidRef")
			{
				// guidRef refers a template whose guid value should be persisted
				var templateNode = value as DomNode;
				return templateNode.GetAttribute(Schema.templateType.guidAttribute) as string;
			}

			return base.Convert(node, attributeInfo);
		}
开发者ID:GeertVL,项目名称:ATF,代码行数:12,代码来源:CircuitWriter.cs

示例6: GetVector

        /// <summary>
        /// Gets the DomNode attribute as a Vec3F and returns true, or returns false if the attribute
        /// doesn't exist</summary>
        /// <param name="domNode">DomNode holding the attribute</param>
        /// <param name="attribute">Attribute of the DomNode that contains the data</param>
        /// <param name="result">The resulting Vec3F. Is (0,0,0) if the attribute couldn't be found</param>
        /// <returns>True iff the attribute was found and was converted to a Vec3F</returns>
        public static bool GetVector(DomNode domNode, AttributeInfo attribute, out Vec3F result)
        {
            float[] floats = domNode.GetAttribute(attribute) as float[];
            if (floats != null)
            {
                result = new Vec3F(floats);
                return true;
            }

            result = new Vec3F();
            return false;
        }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:19,代码来源:DomNodeUtil.cs

示例7: Convert

        /// <summary>
        /// Converts attribute to string.
        /// WriteAttributes(..) call this method to convert dom attribute to string
        /// before writing.        
        /// </summary>
        /// <param name="node">DomNode that owns the attribute to be converted</param>
        /// <param name="attributeInfo">The attribute that need to be converted</param>
        /// <returns>the string value of the attribute</returns>
        protected override string Convert(DomNode node, AttributeInfo attributeInfo)
        {
            // if attribute is uri, then convert it to relative if it is absolute.

            string valueString = string.Empty;
            object value = node.GetAttribute(attributeInfo);
            if (value == null) return valueString;

            if (attributeInfo.Type.Type == AttributeTypes.Reference)
            {
                // if reference is a valid node, convert to string
                DomNode refNode = value as DomNode;
                if (refNode != null)
                    valueString = GetNodeReferenceString(refNode, Root, Uri);
            }
            else if (attributeInfo.Type.Type == AttributeTypes.Uri)
            {
                Uri ur = (Uri)value;
                if (ur.IsAbsoluteUri)
                {
                    // todo use schema annotation to choose between resource root and this uri                    
                    if (node.Type == Schema.gameReferenceType.Type
                        || node.Type == Schema.gameObjectReferenceType.Type)
                    {// use this Uri to make it relative.
                        ur = Uri.MakeRelativeUri(ur);
                    }
                    else
                    {// use resource root to make it relative
                        ur = m_resourceRoot.MakeRelativeUri(ur);
                    }

                    ur = new Uri(Uri.UnescapeDataString(ur.ToString()), UriKind.Relative);
                    valueString = ur.ToString();
                }
            }
            else
            {
                valueString = attributeInfo.Type.Convert(value);
            }

            return valueString;
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:50,代码来源:CustomDomXmlWriter.cs

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

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

示例10: GetVector4

 /// <summary>
 /// Gets Vec4F associated with DomNode attribute</summary>
 /// <param name="domNode">DomNode</param>
 /// <param name="attribute">Attribute for Vec4F</param>
 /// <returns>Vec4F associated with DomNode attribute</returns>
 public static Vec4F GetVector4(DomNode domNode, AttributeInfo attribute)
 {
     return new Vec4F(DoubleToFloat(domNode.GetAttribute(attribute) as double[]));
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:9,代码来源:Tools.cs

示例11: GetMatrix

 /// <summary>
 /// Gets the DomNode attribute as a Matrix4F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <returns>DomNode attribute as a Matrix4F</returns>
 public static Matrix4F GetMatrix(DomNode domNode, AttributeInfo attribute)
 {
     return new Matrix4F((float[])domNode.GetAttribute(attribute));
 }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:9,代码来源:DomNodeUtil.cs

示例12: GetMatrix

 /// <summary>
 /// Gets Matrix4F associated with DomNode attribute</summary>
 /// <param name="domNode">DomNode</param>
 /// <param name="attribute">Attribute for Matrix4F</param>
 /// <returns>Matrix4F associated with DomNode attribute</returns>
 public static Matrix4F GetMatrix(DomNode domNode, AttributeInfo attribute)
 {
     return new Matrix4F(DoubleToFloat(domNode.GetAttribute(attribute) as double[]));
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:9,代码来源:Tools.cs

示例13: TestDuplicateAttributeInfo

        public void TestDuplicateAttributeInfo()
        {
            // This would be illegal in a schema file, but it seems to be supported OK in the DOM.
            var attr1 = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var attr2 = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var domType = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { attr1, attr2 },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            var domNode = new DomNode(domType);
            
            var originalAttr1 = "setting attr1";
            var originalAttr2 = "setting attr2";

            domNode.SetAttribute(attr1, originalAttr1);
            domNode.SetAttribute(attr2, originalAttr2);

            string resultAttr1 = (string)domNode.GetAttribute(attr1);
            string resultAttr2 = (string)domNode.GetAttribute(attr2);

            Assert.IsTrue(string.Equals(resultAttr1,originalAttr1));
            Assert.IsTrue(string.Equals(resultAttr2, originalAttr2));
        }
开发者ID:sbambach,项目名称:ATF,代码行数:26,代码来源:TestDomNodeType.cs

示例14: ProcessValueInfo

            private void ProcessValueInfo(DomNode valInfo, string propName,
                List<System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type type = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {

                    TypeConverter converter;
                    object editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                            , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {

                                // special handling for SyntaxEditorControl
                                if (typeName == "Sce.Atf.Controls.SyntaxEditorControl.TextHighlightStyle")
                                {
                                    string argName =
                                    (string)vInfoChildList[0].GetAttribute(SkinSchema.valueInfoType.valueAttribute);

                                    string name = propName + "->" + argName;
                                    ProcessValueInfo(vInfoChildList[1], name, descriptors);
                                }
                                else
                                {
                                    int k = 1;
                                    string paramName = propName + " : Arg_";
                                    foreach (DomNode vInfoChild in vInfoChildList)
                                    {
                                        string name = paramName + k;
                                        ProcessValueInfo(vInfoChild, name, descriptors);
                                        k++;
                                    }
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }
开发者ID:Joxx0r,项目名称:ATF,代码行数:68,代码来源:SkinEditor.cs

示例15: WriteResource

        private static void WriteResource(DomNode resourceNode, StreamWriter writer)
        {
            StringBuilder lineBuilder = new StringBuilder( string.Format(
                "resource type=\"{0}\", name=\"{1}\"",
                resourceNode.Type.Name,
                resourceNode.GetAttribute(DomTypes.resourceType.nameAttribute)));

            WriteAttribute(resourceNode, "size", lineBuilder);
            WriteAttribute(resourceNode, "compressed", lineBuilder);

            if (resourceNode.Type == DomTypes.geometryResourceType.Type)
            {
                WriteAttribute(resourceNode, "bones", lineBuilder);
                WriteAttribute(resourceNode, "vertices", lineBuilder);
                WriteAttribute(resourceNode, "primitiveType", lineBuilder);
            }
            else if (resourceNode.Type == DomTypes.animationResourceType.Type)
            {
                WriteAttribute(resourceNode, "tracks", lineBuilder);
                WriteAttribute(resourceNode, "duration", lineBuilder);
            }
            else
                throw new InvalidOperationException("unknown resource type");
            
            writer.WriteLine(lineBuilder.ToString());
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:26,代码来源:EventSequenceDocument.cs


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