Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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, 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 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 )
{
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 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" );
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// 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 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 )
{
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 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" );
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StrongTypingException.cs
- RegexWorker.cs
- ExpressionParser.cs
- DataGridViewCellPaintingEventArgs.cs
- EdmSchemaAttribute.cs
- TokenizerHelper.cs
- MouseCaptureWithinProperty.cs
- Cursor.cs
- CodeSnippetExpression.cs
- Misc.cs
- TypedReference.cs
- TextBlock.cs
- InternalConfigEventArgs.cs
- HostedHttpContext.cs
- StrokeCollection.cs
- PathNode.cs
- UnsignedPublishLicense.cs
- ProgressChangedEventArgs.cs
- ListCollectionView.cs
- StyleCollectionEditor.cs
- StoreContentChangedEventArgs.cs
- UrlPath.cs
- HyperLink.cs
- XmlAttributeCache.cs
- TextElementEnumerator.cs
- NetCodeGroup.cs
- IOException.cs
- SoapIncludeAttribute.cs
- SyntaxCheck.cs
- KnownTypeDataContractResolver.cs
- SafeNativeMethods.cs
- GridViewCancelEditEventArgs.cs
- __Filters.cs
- DataContractSet.cs
- CommandConverter.cs
- TargetFrameworkAttribute.cs
- TimeoutValidationAttribute.cs
- ToolStripControlHost.cs
- LocalizabilityAttribute.cs
- PhysicalAddress.cs
- StringAttributeCollection.cs
- LayoutInformation.cs
- XmlReturnReader.cs
- LowerCaseStringConverter.cs
- InstanceContext.cs
- ArraySegment.cs
- Utils.cs
- XmlElementAttribute.cs
- SystemSounds.cs
- ContentElement.cs
- TypeRestriction.cs
- SubMenuStyleCollection.cs
- XmlDataProvider.cs
- PixelFormats.cs
- ButtonFlatAdapter.cs
- DataSourceCacheDurationConverter.cs
- SemanticAnalyzer.cs
- DbDataAdapter.cs
- CultureData.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- CheckBoxList.cs
- HtmlEmptyTagControlBuilder.cs
- XmlNamespaceMapping.cs
- Vector3DIndependentAnimationStorage.cs
- Int32Collection.cs
- columnmapkeybuilder.cs
- StickyNoteContentControl.cs
- _LocalDataStoreMgr.cs
- EdmItemError.cs
- SimpleExpression.cs
- ResourceSet.cs
- TreeNodeConverter.cs
- HyperLink.cs
- ToolTip.cs
- CultureMapper.cs
- RegexGroup.cs
- IndexedEnumerable.cs
- EntityDataSourceSelectingEventArgs.cs
- ipaddressinformationcollection.cs
- DataGridItemCollection.cs
- KeyedHashAlgorithm.cs
- DebugInfoGenerator.cs
- EmptyStringExpandableObjectConverter.cs
- FormatException.cs
- CodeDelegateInvokeExpression.cs
- CodeTypeConstructor.cs
- shaperfactoryquerycacheentry.cs
- SiteMapHierarchicalDataSourceView.cs
- TrackingProfileManager.cs
- ProjectionPruner.cs
- DesignerProperties.cs
- baseshape.cs
- RotationValidation.cs
- ButtonField.cs
- DataGridViewCellValueEventArgs.cs
- SqlInfoMessageEvent.cs
- WebPartConnectionsCancelEventArgs.cs
- Zone.cs
- columnmapfactory.cs
- ModulesEntry.cs