/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
/// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
/// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
/// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
public override IPermission Intersect(IPermission target)
{
ReflectionPermission reflectionPermission = this.Cast(target);
if (reflectionPermission == null)
{
return(null);
}
if (this.IsUnrestricted())
{
if (reflectionPermission.Flags == ReflectionPermissionFlag.NoFlags)
{
return(null);
}
return(reflectionPermission.Copy());
}
else
{
if (!reflectionPermission.IsUnrestricted())
{
ReflectionPermission reflectionPermission2 = (ReflectionPermission)reflectionPermission.Copy();
reflectionPermission2.Flags &= this.flags;
return((reflectionPermission2.Flags != ReflectionPermissionFlag.NoFlags) ? reflectionPermission2 : null);
}
if (this.flags == ReflectionPermissionFlag.NoFlags)
{
return(null);
}
return(this.Copy());
}
}