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

Attribute() public method

public Attribute ( string name ) : string
name string
return string
        public string Attribute(string name)
        {
            if (name == null)
                throw new ArgumentNullException(nameof(name));

            // Note: we don't check for validity here because an
            // if an invalid name is passed we simply won't find it.
            if (_attributes == null)
                return null;

            // Go through all the attribute and see if we know about
            // the one we are asked for
            int iMax = _attributes.Count;
            Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");

            for (int i = 0; i < iMax; i += 2)
            {
                string strAttrName = (string)_attributes[i];

                if (string.Equals(strAttrName, name))
                {
                    string strAttrValue = (string)_attributes[i + 1];

                    return Unescape(strAttrValue);
                }
            }

            // In the case where we didn't find it, we are expected to
            // return null
            return null;
        }

Usage Example

	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				String value;
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(S._("Arg_PermissionVersion"));
				}
				value = esd.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					state = PermissionState.Unrestricted;
				}
				else
				{
					state = PermissionState.None;
				}
				value = esd.Attribute("Level");
				if(value != null)
				{
					level = (PrintingPermissionLevel)
						Enum.Parse(typeof(PrintingPermissionLevel), value);
				}
				else
				{
					level = PrintingPermissionLevel.NoPrinting;
				}
			}
All Usage Examples Of System.Security.SecurityElement::Attribute