Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / clr / src / BCL / System / Security / Policy / URLMembershipCondition.cs / 2 / 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, IReportMatchMembershipCondition { //------------------------------------------------------ // // 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 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 ) { object usedEvidence = null; return (this as IReportMatchMembershipCondition).Check(evidence, out usedEvidence); } bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence) { usedEvidence = null; 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 )) { usedEvidence = enumerator.Current; 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 assertt 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 assertt 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" ); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SamlAttributeStatement.cs
- GeneralTransform.cs
- BridgeDataRecord.cs
- PathStreamGeometryContext.cs
- CompositeKey.cs
- SingleResultAttribute.cs
- BaseConfigurationRecord.cs
- DataGridViewComboBoxColumn.cs
- SimpleParser.cs
- SpecialFolderEnumConverter.cs
- QueryAsyncResult.cs
- DataGridItem.cs
- DetailsViewDeletedEventArgs.cs
- HtmlTableRow.cs
- TextRunProperties.cs
- SqlParameterizer.cs
- DataGrid.cs
- EnumValAlphaComparer.cs
- WorkflowApplicationAbortedEventArgs.cs
- XsdDateTime.cs
- DesignerLabelAdapter.cs
- PropertyInfoSet.cs
- InheritedPropertyChangedEventArgs.cs
- LockCookie.cs
- ZipPackage.cs
- ButtonColumn.cs
- ServiceProviders.cs
- IgnoreFileBuildProvider.cs
- NeutralResourcesLanguageAttribute.cs
- dataprotectionpermissionattribute.cs
- CodeBinaryOperatorExpression.cs
- StrongNameUtility.cs
- FullTrustAssembly.cs
- X509ServiceCertificateAuthentication.cs
- StatusBarPanel.cs
- Compilation.cs
- VarRemapper.cs
- PnrpPermission.cs
- CodeAccessSecurityEngine.cs
- Calendar.cs
- RuleProcessor.cs
- BCLDebug.cs
- TypeDependencyAttribute.cs
- EncryptedXml.cs
- AdornerPresentationContext.cs
- EntryIndex.cs
- MetadataItemEmitter.cs
- Visual.cs
- BinaryConverter.cs
- DataServiceExpressionVisitor.cs
- _DomainName.cs
- SubpageParagraph.cs
- PriorityRange.cs
- XmlSchemaSequence.cs
- SimplePropertyEntry.cs
- NativeMethods.cs
- HtmlControl.cs
- Listener.cs
- ReplyAdapterChannelListener.cs
- PrincipalPermission.cs
- ControlBuilder.cs
- LinqDataSourceStatusEventArgs.cs
- ipaddressinformationcollection.cs
- SafeTokenHandle.cs
- Serializer.cs
- hebrewshape.cs
- ToolStripDesignerAvailabilityAttribute.cs
- TextRenderer.cs
- WindowsRichEditRange.cs
- TransformCryptoHandle.cs
- FloaterBaseParaClient.cs
- TemplatePropertyEntry.cs
- ZoneMembershipCondition.cs
- LayoutTableCell.cs
- CodeBinaryOperatorExpression.cs
- UpDownBaseDesigner.cs
- IdentityHolder.cs
- ObjectResult.cs
- OdbcUtils.cs
- ParseHttpDate.cs
- BitmapCacheBrush.cs
- SqlDataSourceWizardForm.cs
- PnrpPermission.cs
- Point3DValueSerializer.cs
- GiveFeedbackEventArgs.cs
- OdbcConnectionOpen.cs
- mactripleDES.cs
- SmiEventSink_Default.cs
- Function.cs
- JapaneseCalendar.cs
- DataBindingCollection.cs
- Interlocked.cs
- Document.cs
- ProtocolElement.cs
- UnhandledExceptionEventArgs.cs
- DateTimeConstantAttribute.cs
- DataGridViewTextBoxColumn.cs
- XmlWrappingReader.cs
- CombinedGeometry.cs
- DataTableClearEvent.cs