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


C# DomNode.IsAttributeDefault方法代码示例

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


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

示例1: WriteAttribute

 /// <summary>
 /// Appends the attribute, if it's not the default value, in the format ", {name}={value}".
 /// If the value is an integer, then no quotes are used.
 /// If the value is a bool, then true or false are written out, without quotes.
 /// Otherwise, the value is enclosed in quotes.</summary>
 /// <param name="node">Node whose attributes is written</param>
 /// <param name="name">Attribute name</param>
 /// <param name="lineBuilder">String builder to create string attribute data</param>
 private static void WriteAttribute(DomNode node, string name, StringBuilder lineBuilder)
 {
     AttributeInfo attributeInfo = node.Type.GetAttributeInfo(name);
     if (!node.IsAttributeDefault(attributeInfo))
     {
         object attribute = node.GetAttribute(attributeInfo);
         if (attribute is int)
             lineBuilder.AppendFormat(", {0}={1}", name, ((int)attribute).ToString());
         else if (attribute is bool)
             lineBuilder.AppendFormat(", {0}={1}", name, (bool)attribute == true ? "true" : "false");
         else
             lineBuilder.AppendFormat(", {0}=\"{1}\"", name, attribute);
     }
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:22,代码来源:EventSequenceDocument.cs

示例2: ShouldWriteAttribute

 /// <summary>
 /// Determines whether the attribute's value should be persisted</summary>
 /// <returns>true if the attribute's value should be persisted; otherwise, false.</returns>
 protected virtual bool ShouldWriteAttribute(DomNode node, AttributeInfo attributeInfo)
 {
     return PersistDefaultAttributes || !node.IsAttributeDefault(attributeInfo);
 }
开发者ID:vincenthamm,项目名称:ATF,代码行数:7,代码来源:DomXmlWriter.cs

示例3: WriteElement

        /// <summary>
        /// Writes the element corresponding to the DomNode</summary>
        /// <param name="node">DomNode to write</param>
        protected virtual void WriteElement(DomNode node, XmlWriter writer)
        {
            string elementNS = m_typeCollection.TargetNamespace;
            int index = node.ChildInfo.Name.LastIndexOf(':');
            if (index >= 0)
                elementNS = node.ChildInfo.Name.Substring(0, index);

            string elementPrefix = string.Empty;

            // is this the root DomNode?
            if (node.Parent == null)
            {
                elementPrefix = m_typeCollection.GetPrefix(elementNS);
                if (elementPrefix == null)
                    elementPrefix = GeneratePrefix(elementNS);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNS);

                // define the xsi namespace
                writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);

                // define schema namespaces
                foreach (XmlQualifiedName name in m_typeCollection.Namespaces)
                    if (name.Name != elementPrefix) // don't redefine the element namespace
                        writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
            }
            else
            {
                // not the root, so all schema namespaces have been defined
                elementPrefix = writer.LookupPrefix(elementNS);
                if (elementPrefix == null)
                    elementPrefix = GeneratePrefix(elementNS);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNS);
            }

            // write type name if this is a polymorphic type
            DomNodeType type = node.Type;
            if (node.ChildInfo.Type != type)
            {
                string name = type.Name;
                index = name.LastIndexOf(':');
                if (index >= 0)
                {
                    string typeName = name.Substring(index + 1, type.Name.Length - index - 1);
                    string typeNS = name.Substring(0, index);
                    string typePrefix = writer.LookupPrefix(typeNS);
                    if (typePrefix == null)
                    {
                        typePrefix = GeneratePrefix(typeNS);
                        writer.WriteAttributeString("xmlns", typePrefix, null, typeNS);
                    }

                    name = typeName;
                    if (typePrefix != string.Empty)
                        name = typePrefix + ":" + typeName;
                }

                writer.WriteAttributeString("xsi", "type", XmlSchema.InstanceNamespace, name);
            }

            // write attributes
            AttributeInfo valueAttribute = null;
            foreach (AttributeInfo attributeInfo in type.Attributes)
            {
                // if attribute is required, or not the default, write it
                if (/*attributeInfo.Required ||*/ !node.IsAttributeDefault(attributeInfo))
                {
                    if (attributeInfo.Name == string.Empty)
                    {
                        valueAttribute = attributeInfo;
                    }
                    else
                    {
                        object value = node.GetAttribute(attributeInfo);
                        string valueString = null;
                        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, m_root, m_uri);
                        }
                        if (valueString == null)
                            valueString = attributeInfo.Type.Convert(value);

                        writer.WriteAttributeString(attributeInfo.Name, valueString);
                    }
                }
            }

            // write value if not the default
            if (valueAttribute != null)
            {
                object value = node.GetAttribute(valueAttribute);
                writer.WriteString(valueAttribute.Type.Convert(value));
            }
//.........这里部分代码省略.........
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:101,代码来源:XmlPersister.cs

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

示例5: WriteElement

        private void WriteElement(DomNode node, XmlWriter writer)
        {
            // If writing the project settings file...
            if (!m_bWritingUserSettings)
            {
                // Don't save types that are not supposed to be saved
                if (s_lstExcludeDomNodeTypes.Contains(node.Type))
                    return;
            }

            var elementNs = m_typeCollection.TargetNamespace;
            var index = node.ChildInfo.Name.LastIndexOf(':');
            if (index >= 0)
                elementNs = node.ChildInfo.Name.Substring(0, index);

            string elementPrefix;

            // is this the root DomNode (the one passed Write, above)?
            if (node == m_root)
            {
                elementPrefix = m_typeCollection.GetPrefix(elementNs) ?? GeneratePrefix(elementNs);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNs);

                // define the xsi namespace
                writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);

                // define schema namespaces
                foreach (var name in m_typeCollection.Namespaces)
                {
                    if (string.Compare(name.Name, elementPrefix) != 0)
                        writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
                }
            }
            else
            {
                // not the root, so all schema namespaces have been defined
                elementPrefix = writer.LookupPrefix(elementNs) ?? GeneratePrefix(elementNs);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNs);
            }

            // write type name if this is a polymorphic type
            var type = node.Type;
            if (node.ChildInfo.Type != type)
            {
                var name = type.Name;
                index = name.LastIndexOf(':');
                if (index >= 0)
                {
                    var typeName = name.Substring(index + 1, type.Name.Length - index - 1);
                    var typeNs = name.Substring(0, index);
                    var typePrefix = writer.LookupPrefix(typeNs);
                    if (typePrefix == null)
                    {
                        typePrefix = GeneratePrefix(typeNs);
                        writer.WriteAttributeString("xmlns", typePrefix, null, typeNs);
                    }

                    name = typeName;
                    if (typePrefix != string.Empty)
                        name = typePrefix + ":" + typeName;
                }

                writer.WriteAttributeString("xsi", "type", XmlSchema.InstanceNamespace, name);
            }

            // write attributes
            AttributeInfo valueAttribute = null;
            foreach (var attributeInfo in type.Attributes)
            {
                // if attribute is required, or not the default, write it
                if (/*attributeInfo.Required ||*/ !node.IsAttributeDefault(attributeInfo))
                {
                    if (attributeInfo.Name == string.Empty)
                    {
                        valueAttribute = attributeInfo;
                    }
                    else
                    {
                        var value = node.GetAttribute(attributeInfo);
                        string valueString = null;
                        if (attributeInfo.Type.Type == AttributeTypes.Reference)
                        {
                            // if reference is a valid node, convert to string
                            var refNode = value as DomNode;
                            if (refNode != null)
                                valueString = GetNodeReferenceString(refNode, m_root);
                        }
                        if (valueString == null)
                            valueString = attributeInfo.Type.Convert(value);

                        var bWriteAttribute = true;
                        if (!m_bWritingUserSettings)
                            bWriteAttribute = !s_lstExcludeAttributes.Contains(attributeInfo.Name);

                        if (bWriteAttribute)
                            writer.WriteAttributeString(attributeInfo.Name, valueString);
                    }
                }
//.........这里部分代码省略.........
开发者ID:arsaccol,项目名称:SLED,代码行数:101,代码来源:SledSpfReaderWriter.cs


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