コード例 #1
0
 /// <summary>Finds an attribute by name in an XML element.</summary>
 /// <returns>The value associated with the named attribute, or null if no attribute with <paramref name="name" /> exists.</returns>
 /// <param name="name">The name of the attribute for which to search. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception>
 public string Attribute(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     SecurityElement.SecurityAttribute attribute = this.GetAttribute(name);
     return((attribute != null) ? attribute.Value : null);
 }
コード例 #2
0
 internal SecurityElement.SecurityAttribute GetAttribute(string name)
 {
     if (this.attributes != null)
     {
         foreach (object obj in this.attributes)
         {
             SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
             if (securityAttribute.Name == name)
             {
                 return(securityAttribute);
             }
         }
     }
     return(null);
 }
コード例 #3
0
 internal SecurityElement(SecurityElement se)
 {
     this.Tag  = se.Tag;
     this.Text = se.Text;
     if (se.attributes != null)
     {
         foreach (object obj in se.attributes)
         {
             SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
             this.AddAttribute(securityAttribute.Name, securityAttribute.Value);
         }
     }
     if (se.children != null)
     {
         foreach (object obj2 in se.children)
         {
             SecurityElement child = (SecurityElement)obj2;
             this.AddChild(child);
         }
     }
 }
コード例 #4
0
 private void ToXml(ref StringBuilder s, int level)
 {
     s.Append("<");
     s.Append(this.tag);
     if (this.attributes != null)
     {
         s.Append(" ");
         for (int i = 0; i < this.attributes.Count; i++)
         {
             SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute) this.attributes[i];
             s.Append(securityAttribute.Name).Append("=\"").Append(SecurityElement.Escape(securityAttribute.Value)).Append("\"");
             if (i != this.attributes.Count - 1)
             {
                 s.Append(Environment.NewLine);
             }
         }
     }
     if ((this.text == null || this.text == string.Empty) && (this.children == null || this.children.Count == 0))
     {
         s.Append("/>").Append(Environment.NewLine);
     }
     else
     {
         s.Append(">").Append(SecurityElement.Escape(this.text));
         if (this.children != null)
         {
             s.Append(Environment.NewLine);
             foreach (object obj in this.children)
             {
                 SecurityElement securityElement = (SecurityElement)obj;
                 securityElement.ToXml(ref s, level + 1);
             }
         }
         s.Append("</").Append(this.tag).Append(">").Append(Environment.NewLine);
     }
 }
コード例 #5
0
 /// <summary>Compares two XML element objects for equality.</summary>
 /// <returns>true if the tag, attribute names and values, child elements, and text fields in the current XML element are identical to their counterparts in the <paramref name="other" /> parameter; otherwise, false.</returns>
 /// <param name="other">An XML element object to which to compare the current XML element object. </param>
 public bool Equal(SecurityElement other)
 {
     if (other == null)
     {
         return(false);
     }
     if (this == other)
     {
         return(true);
     }
     if (this.text != other.text)
     {
         return(false);
     }
     if (this.tag != other.tag)
     {
         return(false);
     }
     if (this.attributes == null && other.attributes != null && other.attributes.Count != 0)
     {
         return(false);
     }
     if (other.attributes == null && this.attributes != null && this.attributes.Count != 0)
     {
         return(false);
     }
     if (this.attributes != null && other.attributes != null)
     {
         if (this.attributes.Count != other.attributes.Count)
         {
             return(false);
         }
         foreach (object obj in this.attributes)
         {
             SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
             SecurityElement.SecurityAttribute attribute         = other.GetAttribute(securityAttribute.Name);
             if (attribute == null || securityAttribute.Value != attribute.Value)
             {
                 return(false);
             }
         }
     }
     if (this.children == null && other.children != null && other.children.Count != 0)
     {
         return(false);
     }
     if (other.children == null && this.children != null && this.children.Count != 0)
     {
         return(false);
     }
     if (this.children != null && other.children != null)
     {
         if (this.children.Count != other.children.Count)
         {
             return(false);
         }
         for (int i = 0; i < this.children.Count; i++)
         {
             if (!((SecurityElement)this.children[i]).Equal((SecurityElement)other.children[i]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }