/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.IsSubsetOf"]/*' />
/// <devdoc>
/// <para>Compares two <see cref='System.Net.WebPermission'/> instances.</para>
/// </devdoc>
public override bool IsSubsetOf(IPermission target)
{
// Pattern suggested by security engine
if (target == null)
{
return(m_noRestriction == false && m_connectList.Count == 0 && m_acceptList.Count == 0);
}
WebPermission other = target as WebPermission;
if (other == null)
{
throw new ArgumentException(SR.GetString(SR.net_perm_target));
}
if (other.IsUnrestricted())
{
return(true);
}
else if (this.IsUnrestricted())
{
return(false);
}
else if (this.m_acceptList.Count + this.m_connectList.Count == 0)
{
return(true);
}
else if (other.m_acceptList.Count + other.m_connectList.Count == 0)
{
return(false);
}
//
// Besides SPECIAL case, this method is restricted to only final URIs (strings) on
// the current object.
// The restriction comes from the problem of finding a Regex to be a subset of another Regex
//
String UriString = null;
foreach (object Uri in this.m_acceptList)
{
UriString = Uri as String;
if (UriString == null)
{
if (isSpecialSubsetCase(Uri.ToString(), other.m_acceptList))
{
continue;
}
throw new NotSupportedException(SR.GetString(SR.net_perm_both_regex));
}
if (!isMatchedURI(UriString, other.m_acceptList))
{
return(false);
}
}
foreach (object Uri in this.m_connectList)
{
UriString = Uri as String;
if (UriString == null)
{
if (isSpecialSubsetCase(Uri.ToString(), other.m_connectList))
{
continue;
}
throw new NotSupportedException(SR.GetString(SR.net_perm_both_regex));
}
if (!isMatchedURI(UriString, other.m_connectList))
{
return(false);
}
}
return(true);
}