diff options
Diffstat (limited to 'src/mscorlib/src/System/Security/SecurityElement.cs')
-rw-r--r-- | src/mscorlib/src/System/Security/SecurityElement.cs | 100 |
1 files changed, 23 insertions, 77 deletions
diff --git a/src/mscorlib/src/System/Security/SecurityElement.cs b/src/mscorlib/src/System/Security/SecurityElement.cs index aa63029422..f57665b278 100644 --- a/src/mscorlib/src/System/Security/SecurityElement.cs +++ b/src/mscorlib/src/System/Security/SecurityElement.cs @@ -14,6 +14,7 @@ namespace System.Security using System.Globalization; using System.IO; using System.Security.Permissions; + using System.Diagnostics; using System.Diagnostics.Contracts; internal enum SecurityElementType @@ -93,23 +94,10 @@ namespace System.Security return ((SecurityElement)this).Attribute( attributeName ); } -////////////// - -#if FEATURE_CAS_POLICY - public static SecurityElement FromString( String xml ) - { - if (xml == null) - throw new ArgumentNullException( "xml" ); - Contract.EndContractBlock(); - - return new Parser( xml ).GetTopElement(); - } -#endif // FEATURE_CAS_POLICY - public SecurityElement( String tag ) { if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); if (!IsValidTag( tag )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementTag" ), tag ) ); @@ -122,7 +110,7 @@ namespace System.Security public SecurityElement( String tag, String text ) { if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); if (!IsValidTag( tag )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementTag" ), tag ) ); @@ -148,7 +136,7 @@ namespace System.Security set { if (value == null) - throw new ArgumentNullException( "Tag" ); + throw new ArgumentNullException( nameof(Tag) ); if (!IsValidTag( value )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementTag" ), value ) ); @@ -171,7 +159,7 @@ namespace System.Security Hashtable hashtable = new Hashtable( m_lAttributes.Count/2 ); int iMax = m_lAttributes.Count; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + 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) { @@ -296,7 +284,7 @@ namespace System.Security else { int iMax = m_lAttributes.Count; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + 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) { @@ -314,10 +302,10 @@ namespace System.Security public void AddAttribute( String name, String value ) { if (name == null) - throw new ArgumentNullException( "name" ); + throw new ArgumentNullException( nameof(name) ); if (value == null) - throw new ArgumentNullException( "value" ); + throw new ArgumentNullException( nameof(value) ); if (!IsValidAttributeName( name )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementName" ), name ) ); @@ -332,7 +320,7 @@ namespace System.Security public void AddChild( SecurityElement child ) { if (child == null) - throw new ArgumentNullException( "child" ); + throw new ArgumentNullException( nameof(child) ); Contract.EndContractBlock(); if (m_lChildren == null) @@ -344,7 +332,7 @@ namespace System.Security internal void AddChild( ISecurityElementFactory child ) { if (child == null) - throw new ArgumentNullException( "child" ); + throw new ArgumentNullException( nameof(child) ); Contract.EndContractBlock(); if (m_lChildren == null) @@ -356,7 +344,7 @@ namespace System.Security internal void AddChildNoDuplicates( ISecurityElementFactory child ) { if (child == null) - throw new ArgumentNullException( "child" ); + throw new ArgumentNullException( nameof(child) ); Contract.EndContractBlock(); if (m_lChildren == null) @@ -400,7 +388,7 @@ namespace System.Security else { int iMax = m_lAttributes.Count; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + Debug.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); if (iMax != other.m_lAttributes.Count) return false; @@ -495,7 +483,7 @@ namespace System.Security private static String GetEscapeSequence( char c ) { int iMax = s_escapeStringPairs.Length; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + 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) { @@ -506,7 +494,7 @@ namespace System.Security return strEscValue; } - Contract.Assert( false, "Unable to find escape sequence for this character" ); + Debug.Assert( false, "Unable to find escape sequence for this character" ); return c.ToString(); } @@ -557,7 +545,7 @@ namespace System.Security int maxCompareLength = str.Length - index; int iMax = s_escapeStringPairs.Length; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + 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) { @@ -616,7 +604,7 @@ namespace System.Security while (true); // C# reports a warning if I leave this in, but I still kinda want to just in case. - // Contract.Assert( false, "If you got here, the execution engine or compiler is really confused" ); + // Debug.Assert( false, "If you got here, the execution engine or compiler is really confused" ); // return str; } @@ -626,11 +614,6 @@ namespace System.Security { ((StringBuilder)obj).Append( str ); } - - private static void ToStringHelperStreamWriter( Object obj, String str ) - { - ((StreamWriter)obj).Write( str ); - } public override String ToString () { @@ -641,16 +624,11 @@ namespace System.Security return sb.ToString(); } - internal void ToWriter( StreamWriter writer ) - { - ToString( "", writer, new ToStringHelperFunc( ToStringHelperStreamWriter ) ); - } - private void ToString( String indent, Object obj, ToStringHelperFunc func ) { // First add the indent - // func( obj, indent ); + // func( obj, indent ); // Add in the opening bracket and the tag. @@ -679,7 +657,7 @@ namespace System.Security func( obj, " " ); int iMax = m_lAttributes.Count; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + 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) { @@ -770,7 +748,7 @@ namespace System.Security public String Attribute( String name ) { if (name == null) - throw new ArgumentNullException( "name" ); + throw new ArgumentNullException( nameof(name) ); Contract.EndContractBlock(); // Note: we don't check for validity here because an @@ -783,7 +761,7 @@ namespace System.Security // the one we are asked for int iMax = m_lAttributes.Count; - Contract.Assert( iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly" ); + 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) { @@ -808,7 +786,7 @@ namespace System.Security // find the one are are asked for (matching tags) if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); Contract.EndContractBlock(); // Note: we don't check for a valid tag here because @@ -829,45 +807,13 @@ namespace System.Security return null; } -#if FEATURE_CAS_POLICY - internal IPermission ToPermission(bool ignoreTypeLoadFailures) - { - IPermission ip = XMLUtil.CreatePermission( this, PermissionState.None, ignoreTypeLoadFailures ); - if (ip == null) - return null; - ip.FromXml(this); - - // Get the permission token here to ensure that the token - // type is updated appropriately now that we've loaded the type. - PermissionToken token = PermissionToken.GetToken( ip ); - Contract.Assert((token.m_type & PermissionTokenType.DontKnow) == 0, "Token type not properly assigned"); - - return ip; - } - - [System.Security.SecurityCritical] // auto-generated - internal Object ToSecurityObject() - { - switch (m_strTag) - { - case "PermissionSet": - PermissionSet pset = new PermissionSet(PermissionState.None); - pset.FromXml(this); - return pset; - - default: - return ToPermission(false); - } - } -#endif // FEATURE_CAS_POLICY - internal String SearchForTextOfLocalName(String strLocalName) { // Search on each child in order and each // child's child, depth-first if (strLocalName == null) - throw new ArgumentNullException( "strLocalName" ); + throw new ArgumentNullException( nameof(strLocalName) ); Contract.EndContractBlock(); // Note: we don't check for a valid tag here because @@ -899,7 +845,7 @@ namespace System.Security // child's child, depth-first if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); Contract.EndContractBlock(); // Note: we don't check for a valid tag here because |