Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Security / Policy / URLMembershipCondition.cs / 1 / URLMembershipCondition.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // UrlMembershipCondition.cs // // Implementation of membership condition for urls // namespace System.Security.Policy { using System; using System.Collections; using System.Globalization; using System.Security; using System.Security.Util; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] sealed public class UrlMembershipCondition : IMembershipCondition, IConstantMembershipCondition { //------------------------------------------------------ // // PRIVATE STATE DATA // //----------------------------------------------------- private URLString m_url; private SecurityElement m_element; //----------------------------------------------------- // // PUBLIC CONSTRUCTORS // //----------------------------------------------------- internal UrlMembershipCondition() { m_url = null; } public UrlMembershipCondition( String url ) { if (url == null) throw new ArgumentNullException( "url" ); // Parse the Url to check that it's valid. m_url = new URLString(url, false /* not parsed */, true /* parse eagerly */); } //------------------------------------------------------ // // PUBLIC ACCESSOR METHODS // //----------------------------------------------------- public String Url { set { if (value == null) throw new ArgumentNullException("value"); m_url = new URLString( value ); } get { if (m_url == null && m_element != null) ParseURL(); return m_url.ToString(); } } //------------------------------------------------------ // // IMEMBERSHIPCONDITION IMPLEMENTATION // //------------------------------------------------------ public bool Check( Evidence evidence ) { if (evidence == null) return false; IEnumerator enumerator = evidence.GetHostEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current is Url) { if (m_url == null && m_element != null) ParseURL(); if (((Url)enumerator.Current).GetURLString().IsSubsetOf( m_url )) { return true; } } } return false; } public IMembershipCondition Copy() { if (m_url == null && m_element != null) ParseURL(); UrlMembershipCondition mc = new UrlMembershipCondition(); mc.m_url = new URLString( m_url.ToString() ); return mc; } public SecurityElement ToXml() { return ToXml( null ); } public void FromXml( SecurityElement e ) { FromXml( e, null ); } public SecurityElement ToXml( PolicyLevel level ) { if (m_url == null && m_element != null) ParseURL(); SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.UrlMembershipCondition" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. BCLDebug.Assert( this.GetType().FullName.Equals( "System.Security.Policy.UrlMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); if (m_url != null) root.AddAttribute( "Url", m_url.ToString() ); return root; } public void FromXml( SecurityElement e, PolicyLevel level ) { if (e == null) throw new ArgumentNullException("e"); if (!e.Tag.Equals( "IMembershipCondition" )) { throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) ); } lock (this) { m_element = e; m_url = null; } } private void ParseURL() { lock (this) { if (m_element == null) return; String elurl = m_element.Attribute( "Url" ); if (elurl == null) throw new ArgumentException( Environment.GetResourceString( "Argument_UrlCannotBeNull" ) ); else m_url = new URLString( elurl ); m_element = null; } } public override bool Equals( Object o ) { UrlMembershipCondition that = (o as UrlMembershipCondition); if (that != null) { if (this.m_url == null && this.m_element != null) this.ParseURL(); if (that.m_url == null && that.m_element != null) that.ParseURL(); if (Equals( this.m_url, that.m_url )) { return true; } } return false; } public override int GetHashCode() { if (m_url == null && m_element != null) ParseURL(); if (m_url != null) { return m_url.GetHashCode(); } else { return typeof( UrlMembershipCondition ).GetHashCode(); } } public override String ToString() { if (m_url == null && m_element != null) ParseURL(); if (m_url != null) return String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Url_ToStringArg" ), m_url.ToString() ); else return Environment.GetResourceString( "Url_ToString" ); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _SecureChannel.cs
- _Connection.cs
- ImageDrawing.cs
- SQLMoney.cs
- PreloadedPackages.cs
- MarkupExtensionParser.cs
- HttpPostedFile.cs
- Columns.cs
- IndexerNameAttribute.cs
- ThicknessAnimationBase.cs
- InvalidEnumArgumentException.cs
- StrongNameKeyPair.cs
- StateWorkerRequest.cs
- CaseInsensitiveComparer.cs
- PasswordRecovery.cs
- Int32.cs
- DoubleLink.cs
- FeatureAttribute.cs
- DataGridViewComboBoxColumnDesigner.cs
- X509Utils.cs
- StructuredTypeEmitter.cs
- HtmlForm.cs
- TextServicesProperty.cs
- ScopelessEnumAttribute.cs
- GregorianCalendar.cs
- MediaEntryAttribute.cs
- MessageSmuggler.cs
- ControlCodeDomSerializer.cs
- DBNull.cs
- ToolZone.cs
- FixedStringLookup.cs
- EntitySqlException.cs
- XmlSchemaInclude.cs
- MobileCategoryAttribute.cs
- WebRequestModuleElement.cs
- InvalidOleVariantTypeException.cs
- SiteMapSection.cs
- sitestring.cs
- DataService.cs
- SystemColors.cs
- X509ImageLogo.cs
- PropertyDescriptorCollection.cs
- Int16Animation.cs
- DataGridViewCheckBoxCell.cs
- SendKeys.cs
- Resources.Designer.cs
- TypeConverterAttribute.cs
- ProcessThreadDesigner.cs
- Preprocessor.cs
- TableCell.cs
- JapaneseLunisolarCalendar.cs
- ToolStripStatusLabel.cs
- VectorValueSerializer.cs
- WaitForChangedResult.cs
- MemoryFailPoint.cs
- HitTestDrawingContextWalker.cs
- KerberosRequestorSecurityToken.cs
- DataGridViewRowHeaderCell.cs
- CustomValidator.cs
- FigureHelper.cs
- XPathNavigator.cs
- SmiRecordBuffer.cs
- ApplicationProxyInternal.cs
- PerformanceCounter.cs
- EnumUnknown.cs
- XmlHierarchicalDataSourceView.cs
- BaseInfoTable.cs
- ExpressionVisitorHelpers.cs
- Ops.cs
- DeadCharTextComposition.cs
- RedistVersionInfo.cs
- SocketPermission.cs
- CookielessHelper.cs
- filewebresponse.cs
- CompileLiteralTextParser.cs
- InteropExecutor.cs
- RecordsAffectedEventArgs.cs
- HScrollProperties.cs
- RepeaterItemEventArgs.cs
- DescendantQuery.cs
- RouteCollection.cs
- WebBrowserPermission.cs
- LocalizableResourceBuilder.cs
- TypeDelegator.cs
- SmiEventSink_DeferedProcessing.cs
- ISO2022Encoding.cs
- CodeGenerator.cs
- Aggregates.cs
- HwndSourceParameters.cs
- ProcessDesigner.cs
- XmlSchemaComplexType.cs
- HexParser.cs
- sortedlist.cs
- CodeTypeReferenceExpression.cs
- TextLineBreak.cs
- EmptyReadOnlyDictionaryInternal.cs
- WrappedReader.cs
- BrowserDefinition.cs
- XPathNavigatorKeyComparer.cs
- HostSecurityManager.cs