Export (0) Print
Expand All

PublisherIdentityPermission.IsSubsetOf Method

Determines whether the current permission is a subset of the specified permission.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

public override bool IsSubsetOf (
	IPermission target
)
public boolean IsSubsetOf (
	IPermission target
)
public override function IsSubsetOf (
	target : IPermission
) : boolean
Not applicable.

Parameters

target

A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission.

Return Value

true if the current permission is a subset of the specified permission; otherwise, false.

Exception typeCondition

ArgumentException

The target parameter is not a null reference (Nothing in Visual Basic) and is not of the same type as the current permission.

The current permission is a subset of the specified permission if the two permissions are equal. If this method returns true, the current permission represents the same access to the protected resource as the specified permission.

PublisherIdentityPermission supports set operations (IsSubsetOf, Intersect, and Union) only when the current permission is equal to the specified permission.

The following code example shows the behavior of the IsSubsetOf method. This example is part of a larger example that is provided for the PublisherIdentityPermission class.

NoteNote:

The code example is intended to show the behavior of the method, not to demonstrate its use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications.

private bool IsSubsetOfDemo()
{

    bool retCode = true;

    String publisher1, publisher2;
    PublisherIdentityPermission pubIdPerm1, pubIdPerm2;

    PublisherGenerator pubGen1 = new PublisherGenerator();
    PublisherGenerator pubGen2 = new PublisherGenerator();

    pubGen1.ResetIndex();
    while (pubGen1.CreatePublisher(out pubIdPerm1, out publisher1))
    {
        if (pubIdPerm1 == null) continue;
        pubGen2.ResetIndex();
        while (pubGen2.CreatePublisher(out pubIdPerm2, out publisher2))
        {
            if (pubIdPerm2 == null) continue;

            try
            {
                // Check for whether either of the publishers is null.
                // An exception will be thrown if either is null.
                if (publisher1 != "null" && publisher2 != "null")
                {
                    if (pubIdPerm1.IsSubsetOf(pubIdPerm2))
                    {
                        Console.WriteLine(pubIdPerm1.Certificate.GetName() +
                            " is a subset of " + pubIdPerm2.Certificate.GetName() + "\n");
                    }
                    else
                    {
                        Console.WriteLine(pubIdPerm1.Certificate.GetName() +
                            " is not a subset of " + pubIdPerm2.Certificate.GetName() + "\n");
                    }
                }

            }
            catch
            {
                Console.WriteLine("An exception was thrown for " + publisher1 + " is a subset of " +
                    publisher2 + "\n.");
                retCode = false;
            }

        }
    }


    return retCode;
}

private boolean IsSubsetOfDemo() 
{
    boolean retCode = true;
    String publisher1 = null;
    String publisher2 = null;
    PublisherIdentityPermission pubIdPerm1 = null; 
    PublisherIdentityPermission pubIdPerm2 = null;
    
    PublisherGenerator pubGen1 =  new PublisherGenerator();
    PublisherGenerator pubGen2 =  new PublisherGenerator();
    
    pubGen1.ResetIndex();
    while(pubGen1.CreatePublisher(pubIdPerm1, publisher1)) {
        if (pubIdPerm1 == null) {
            continue ;
        }
        pubGen2.ResetIndex();
        while(pubGen2.CreatePublisher(pubIdPerm2, publisher2)) {
            if (pubIdPerm2 == null) {
                continue ;
            }
            
            try {
                // Check for whether either of the publishers is null.
                // An exception will be thrown if either is null.
                if (publisher1 != "null" && publisher2 != "null") {
                    if ( pubIdPerm1.IsSubsetOf(pubIdPerm2)  ) {
                        Console.WriteLine((pubIdPerm1.get_Certificate().
                        GetName() + " is a subset of " 
                            + pubIdPerm2.get_Certificate().GetName() 
                            + "\n"));
                    }
                    else {
                        Console.WriteLine((pubIdPerm1.get_Certificate().
                        GetName() + " is not a subset of " 
                            + pubIdPerm2.get_Certificate().GetName() 
                            + "\n"));
                    }
                }
            }
            catch(System.Exception exp){
                    Console.WriteLine(("An exception was thrown for " 
                        + publisher1 + " is a subset of " + publisher2 
                        + "\n."));
                    retCode = false;
            }
        }
    }
    return retCode ;
} //IsSubsetOfDemo   

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft