System.Security.SecurityElement.Equal C# (CSharp) Method

Equal() public method

public Equal ( SecurityElement other ) : bool
other SecurityElement
return bool
        public bool Equal(SecurityElement other)
        {
            if (other == null)
                return false;

            // Check if the tags are the same
            if (!string.Equals(_tag, other._tag))
                return false;

            // Check if the text is the same
            if (!string.Equals(_text, other._text))
                return false;

            // Check if the attributes are the same and appear in the same
            // order.
            if (_attributes == null || other._attributes == null)
            {
                if (_attributes != other._attributes)
                    return false;
            }
            else
            {
                int iMax = _attributes.Count;
                Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");

                // Maybe we can get away by only checking the number of attributes
                if (iMax != other._attributes.Count)
                    return false;

                for (int i = 0; i < iMax; i++)
                {
                    string lhs = (string)_attributes[i];
                    string rhs = (string)other._attributes[i];

                    if (!string.Equals(lhs, rhs))
                        return false;
                }
            }

            // Finally we must check the child and make sure they are
            // equal and in the same order
            if (_children == null || other._children == null)
            {
                if (_children != other._children)
                    return false;
            }
            else
            {
                // Maybe we can get away by only checking the number of children
                if (_children.Count != other._children.Count)
                    return false;

                ConvertSecurityElementFactories();
                other.ConvertSecurityElementFactories();

                IEnumerator lhs = _children.GetEnumerator();
                IEnumerator rhs = other._children.GetEnumerator();

                SecurityElement e1, e2;
                while (lhs.MoveNext())
                {
                    rhs.MoveNext();
                    e1 = (SecurityElement)lhs.Current;
                    e2 = (SecurityElement)rhs.Current;
                    if (e1 == null || !e1.Equal(e2))
                        return false;
                }
            }
            return true;
        }

Usage Example

Beispiel #1
0
 /// <summary>比较两个 XML 元素对象,确定它们是否相等。</summary>
 /// <returns>如果当前 XML 元素中的标记、特性名和值、子元素以及文本字段与 <paramref name="other" /> 参数中的对等部分相同,则为 true;否则为 false。</returns>
 /// <param name="other">要与当前 XML 元素对象进行比较的 XML 元素对象。</param>
 public bool Equal(SecurityElement other)
 {
     if (other == null || !string.Equals(this.m_strTag, other.m_strTag) || !string.Equals(this.m_strText, other.m_strText))
     {
         return(false);
     }
     if (this.m_lAttributes == null || other.m_lAttributes == null)
     {
         if (this.m_lAttributes != other.m_lAttributes)
         {
             return(false);
         }
     }
     else
     {
         int count = this.m_lAttributes.Count;
         if (count != other.m_lAttributes.Count)
         {
             return(false);
         }
         for (int index = 0; index < count; ++index)
         {
             if (!string.Equals((string)this.m_lAttributes[index], (string)other.m_lAttributes[index]))
             {
                 return(false);
             }
         }
     }
     if (this.m_lChildren == null || other.m_lChildren == null)
     {
         if (this.m_lChildren != other.m_lChildren)
         {
             return(false);
         }
     }
     else
     {
         if (this.m_lChildren.Count != other.m_lChildren.Count)
         {
             return(false);
         }
         this.ConvertSecurityElementFactories();
         other.ConvertSecurityElementFactories();
         IEnumerator enumerator1 = this.m_lChildren.GetEnumerator();
         IEnumerator enumerator2 = other.m_lChildren.GetEnumerator();
         while (enumerator1.MoveNext())
         {
             enumerator2.MoveNext();
             SecurityElement securityElement = (SecurityElement)enumerator1.Current;
             SecurityElement other1          = (SecurityElement)enumerator2.Current;
             if (securityElement == null || !securityElement.Equal(other1))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
All Usage Examples Of System.Security.SecurityElement::Equal