16 private delegate
void ToStringHelperFunc(
object obj,
string str);
18 internal string m_strTag;
20 internal string m_strText;
26 internal SecurityElementType m_type;
28 private static readonly
char[] s_tagIllegalCharacters =
new char[3]
35 private static readonly
char[] s_textIllegalCharacters =
new char[2]
41 private static readonly
char[] s_valueIllegalCharacters =
new char[3]
48 private const string s_strIndent =
" ";
50 private const int c_AttributesTypical = 8;
52 private const int c_ChildrenTypical = 1;
54 private static readonly
string[] s_escapeStringPairs =
new string[10]
68 private static readonly
char[] s_escapeChars =
new char[5]
109 if (m_lAttributes ==
null || m_lAttributes.
Count == 0)
114 int count = m_lAttributes.
Count;
115 for (
int i = 0; i < count; i += 2)
117 hashtable.
Add(m_lAttributes[i], m_lAttributes[i + 1]);
123 if (value ==
null || value.Count == 0)
125 m_lAttributes =
null;
132 string text = (string)enumerator.
Key;
133 string value2 = (
string)enumerator.
Value;
143 arrayList.
Add(value2);
145 m_lAttributes = arrayList;
156 return Unescape(m_strText);
180 ConvertSecurityElementFactories();
190 if (enumerator.
Current ==
null)
200 internal ArrayList InternalChildren => m_lChildren;
206 SecurityElement ISecurityElementFactory.CreateSecurityElement()
211 string ISecurityElementFactory.GetTag()
216 object ISecurityElementFactory.Copy()
221 string ISecurityElementFactory.Attribute(
string attributeName)
223 return Attribute(attributeName);
239 return new Parser(xml).GetTopElement();
283 internal void ConvertSecurityElementFactories()
285 if (m_lChildren ==
null)
289 for (
int i = 0; i < m_lChildren.
Count; i++)
291 ISecurityElementFactory securityElementFactory = m_lChildren[i] as ISecurityElementFactory;
292 if (securityElementFactory !=
null && !(m_lChildren[i] is SecurityElement))
294 m_lChildren[i] = securityElementFactory.CreateSecurityElement();
299 internal void AddAttributeSafe(
string name,
string value)
301 if (m_lAttributes ==
null)
307 int count = m_lAttributes.
Count;
308 for (
int i = 0; i < count; i += 2)
310 string a = (string)m_lAttributes[i];
311 if (
string.Equals(a, name))
313 throw new ArgumentException(Environment.GetResourceString(
"Argument_AttributeNamesMustBeUnique"));
317 m_lAttributes.
Add(name);
318 m_lAttributes.
Add(value);
344 AddAttributeSafe(name, value);
356 if (m_lChildren ==
null)
360 m_lChildren.
Add(child);
363 internal void AddChild(ISecurityElementFactory child)
369 if (m_lChildren ==
null)
373 m_lChildren.
Add(child);
376 internal void AddChildNoDuplicates(ISecurityElementFactory child)
380 throw new ArgumentNullException(
"child");
382 if (m_lChildren ==
null)
385 m_lChildren.
Add(child);
388 for (
int i = 0; i < m_lChildren.
Count; i++)
390 if (m_lChildren[i] == child)
395 m_lChildren.
Add(child);
408 if (!
string.Equals(m_strTag, other.m_strTag))
412 if (!
string.Equals(m_strText, other.m_strText))
416 if (m_lAttributes ==
null || other.m_lAttributes ==
null)
418 if (m_lAttributes != other.m_lAttributes)
425 int count = m_lAttributes.
Count;
426 if (count != other.m_lAttributes.
Count)
430 for (
int i = 0; i < count; i++)
432 string a = (string)m_lAttributes[i];
433 string b = (string)other.m_lAttributes[i];
434 if (!
string.Equals(a, b))
440 if (m_lChildren ==
null || other.m_lChildren ==
null)
442 if (m_lChildren != other.m_lChildren)
449 if (m_lChildren.
Count != other.m_lChildren.
Count)
453 ConvertSecurityElementFactories();
454 other.ConvertSecurityElementFactories();
462 if (securityElement ==
null || !securityElement.
Equal(other2))
477 securityElement.m_lChildren = ((m_lChildren ==
null) ?
null :
new ArrayList(m_lChildren));
478 securityElement.m_lAttributes = ((m_lAttributes ==
null) ?
null :
new ArrayList(m_lAttributes));
479 return securityElement;
492 return tag.IndexOfAny(s_tagIllegalCharacters) == -1;
505 return text.IndexOfAny(s_textIllegalCharacters) == -1;
527 return value.IndexOfAny(s_valueIllegalCharacters) == -1;
530 private static string GetEscapeSequence(
char c)
532 int num = s_escapeStringPairs.Length;
533 for (
int i = 0; i < num; i += 2)
535 string text = s_escapeStringPairs[i];
536 string result = s_escapeStringPairs[i + 1];
559 int num2 = str.IndexOfAny(s_escapeChars, num);
564 if (stringBuilder ==
null)
568 stringBuilder.
Append(str, num, num2 - num);
569 stringBuilder.
Append(GetEscapeSequence(str[num2]));
572 if (stringBuilder ==
null)
576 stringBuilder.
Append(str, num, length - num);
580 private static string GetUnescapeSequence(
string str,
int index, out
int newIndex)
582 int num = str.Length - index;
583 int num2 = s_escapeStringPairs.Length;
584 for (
int i = 0; i < num2; i += 2)
586 string result = s_escapeStringPairs[i];
587 string text = s_escapeStringPairs[i + 1];
588 int length = text.Length;
589 if (length <= num &&
string.Compare(text, 0, str, index, length,
StringComparison.Ordinal) == 0)
591 newIndex = index + text.Length;
595 newIndex = index + 1;
596 return str[index].ToString();
599 private static string Unescape(
string str)
610 int num = str.IndexOf(
'&', newIndex);
615 if (stringBuilder ==
null)
619 stringBuilder.
Append(str, newIndex, num - newIndex);
620 stringBuilder.
Append(GetUnescapeSequence(str, num, out newIndex));
622 if (stringBuilder ==
null)
626 stringBuilder.
Append(str, newIndex, length - newIndex);
630 private static void ToStringHelperStringBuilder(
object obj,
string str)
635 private static void ToStringHelperStreamWriter(
object obj,
string str)
645 ToString(
"", stringBuilder, ToStringHelperStringBuilder);
651 ToString(
"", writer, ToStringHelperStreamWriter);
654 private void ToString(
string indent,
object obj, ToStringHelperFunc func)
659 case SecurityElementType.Format:
662 case SecurityElementType.Comment:
667 if (m_lAttributes !=
null && m_lAttributes.
Count > 0)
670 int count = m_lAttributes.
Count;
671 for (
int i = 0; i < count; i += 2)
673 string str = (string)m_lAttributes[i];
674 string str2 = (string)m_lAttributes[i + 1];
679 if (i != m_lAttributes.
Count - 2)
681 if (m_type == SecurityElementType.Regular)
683 func(obj, Environment.NewLine);
692 if (m_strText ==
null && (m_lChildren ==
null || m_lChildren.
Count == 0))
696 case SecurityElementType.Comment:
699 case SecurityElementType.Format:
706 func(obj, Environment.NewLine);
710 func(obj, m_strText);
711 if (m_lChildren !=
null)
713 ConvertSecurityElementFactories();
714 func(obj, Environment.NewLine);
715 for (
int j = 0; j < m_lChildren.
Count; j++)
717 ((SecurityElement)m_lChildren[j]).ToString(
"", obj, func);
723 func(obj, Environment.NewLine);
736 if (m_lAttributes ==
null)
740 int count = m_lAttributes.
Count;
741 for (
int i = 0; i < count; i += 2)
743 string a = (string)m_lAttributes[i];
744 if (
string.Equals(a, name))
746 string str = (string)m_lAttributes[i + 1];
747 return Unescape(str);
763 if (m_lChildren ==
null)
771 if (securityElement !=
null &&
string.Equals(securityElement.
Tag, tag))
773 return securityElement;
779 internal IPermission ToPermission(
bool ignoreTypeLoadFailures)
782 if (permission ==
null)
787 PermissionToken token = PermissionToken.GetToken(permission);
792 internal object ToSecurityObject()
794 string strTag = m_strTag;
795 if (strTag ==
"PermissionSet")
798 permissionSet.FromXml(
this);
799 return permissionSet;
801 return ToPermission(ignoreTypeLoadFailures:
false);
804 internal string SearchForTextOfLocalName(
string strLocalName)
806 if (strLocalName ==
null)
808 throw new ArgumentNullException(
"strLocalName");
810 if (m_strTag ==
null)
814 if (m_strTag.Equals(strLocalName) || m_strTag.EndsWith(
":" + strLocalName,
StringComparison.Ordinal))
816 return Unescape(m_strText);
818 if (m_lChildren ==
null)
825 string text = ((SecurityElement)enumerator.
Current).SearchForTextOfLocalName(strLocalName);
845 if (
string.Equals(m_strTag, tag))
847 return Unescape(m_strText);
849 if (m_lChildren ==
null)
854 ConvertSecurityElementFactories();
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
bool MoveNext()
Advances the enumerator to the next element of the collection.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
SecurityElement(string tag, string text)
Initializes a new instance of the T:System.Security.SecurityElement class with the specified tag and ...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
object Key
Gets the key of the current dictionary entry.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
SecurityElement SearchForChildByTag(string tag)
Finds a child by its tag name.
static bool IsValidAttributeValue(string value)
Determines whether a string is a valid attribute value.
string Tag
Gets or sets the tag name of an XML element.
void FromXml(SecurityElement e)
Reconstructs a security object with a specified state from an XML encoding.
string SearchForTextOfTag(string tag)
Finds a child by its tag name and returns the contained text.
static string Escape(string str)
Replaces invalid XML characters in a string with their valid XML equivalent.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
Implements a T:System.IO.TextWriter for writing characters to a stream in a particular encoding....
Provides information about, and means to manipulate, the current environment and platform....
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Represents the XML object model for encoding security objects. This class cannot be inherited.
Hashtable Attributes
Gets or sets the attributes of an XML element as name/value pairs.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
object Current
Gets the element in the collection at the current position of the enumerator.
string Text
Gets or sets the text within an XML element.
SecurityElement Copy()
Creates and returns an identical copy of the current T:System.Security.SecurityElement object.
static bool IsValidText(string text)
Determines whether a string is valid as text within an XML element.
Defines methods implemented by permission types.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
SecurityElement(string tag)
Initializes a new instance of the T:System.Security.SecurityElement class with the specified tag.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
The exception that is thrown when one of the arguments provided to a method is not valid.
static SecurityElement FromString(string xml)
Creates a security element from an XML-encoded string.
string Attribute(string name)
Finds an attribute by name in an XML element.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
bool Equal(SecurityElement other)
Compares two XML element objects for equality.
object Value
Gets the value of the current dictionary entry.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
Enumerates the elements of a nongeneric dictionary.
ArrayList Children
Gets or sets the array of child elements of the XML element.
virtual IEnumerator GetEnumerator()
Returns an enumerator for the entire T:System.Collections.ArrayList.
Provides information about a specific culture (called a locale for unmanaged code development)....
static bool IsValidAttributeName(string name)
Determines whether a string is a valid attribute name.
static bool IsValidTag(string tag)
Determines whether a string is a valid tag.
Supports a simple iteration over a non-generic collection.
override string ToString()
Produces a string representation of an XML element and its constituent attributes,...
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...