System.Security.IPermission Interface

Assembly: Mscorlib.dll
Namespace: System.Security
Summary
Defines methods implemented by permission types.
C# Syntax:
public interface IPermission : ISecurityEncodable
Remarks
Permissions in the common language runtime are objects that describe sets of operations that can be secured for specified resources. A permission object describes operations or access that is subject to security control; it does not represent access or a right to perform operations. Permissions are used by both application code and the .NET Framework security system in the following ways.

Note If you write a new permission, you must implement this interface in your class.
See also:
System.Security Namespace

System.Security.IPermission Member List:

Public Methods
Copy Creates and returns an identical copy of the current permission.
Demand Forces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.
Intersect Creates and returns a permission that is the intersection of the current permission and the specified permission.
IsSubsetOf Determines whether the current permission is a subset of the specified permission.
Union Creates a permission that is the union of the current permission and the specified permission.

Hierarchy:


System.Security.IPermission Member Details

Method: Copy()
Summary
Creates and returns an identical copy of the current permission.
C# Syntax:
IPermission Copy();
Return Value:
A copy of the current permission.
Remarks
A copy of a permission represents the same access to resources as the original permission.

Return to top


Method: Demand()
Summary
Forces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.
C# Syntax:
void Demand();
Remarks
This method is typically used by secure libraries to ensure that callers have permission to access a resource. For example, a file class in a secure class library calls CodeAccessPermission.Demand for the necessary FileIOPermission before performing a file operation requested by the caller.

The permissions of the code that calls this method are not examined; the check begins from the immediate caller of that code and proceeds up the stack. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack. CodeAccessPermission.Demand succeeds only if no SecurityException is raised.

Return to top


Method: Intersect(
   IPermission target
)
Summary
Creates and returns a permission that is the intersection of the current permission and the specified permission.
C# Syntax:
IPermission Intersect(
   IPermission target
);
Parameters:

target

A permission to intersect with the current permission. It must be of the same type as the current permission.

Return Value:
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.
Exceptions
Exception Type Condition
ArgumentException The target parameter is not null and is not an instance of the same class as the current permission.
Remarks
The intersection of two permissions is a permission that describes the set of operations they both describe in common. Only a demand that passes both original permissions will pass the intersection.

The following statements are required to be true for all implementations of the IPermission.Intersect method.X and Y represent IPermission object references that are not null.

Return to top


Method: IsSubsetOf(
   IPermission target
)
Summary
Determines whether the current permission is a subset of the specified permission.
C# Syntax:
bool IsSubsetOf(
   IPermission target
);
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.
Exceptions
Exception Type Condition
ArgumentException The target parameter is not of the same type as the current permission.
Remarks
The current permission is a subset of the specified permission if the current permission specifies a set of operations that is wholly contained by the specified permission. For example, a permission that represents access to C:\example.txt is a subset of a permission that represents access to C:\. If this method returns true, the current permission represents no more access to the protected resource than does the specified permission.

The following statements are required to be true for all implementations of the IPermission.IsSubsetOf method.X, Y, and Z represent IPermission objects that are not null.

Return to top


Method: Union(
   IPermission target
)
Summary
Creates a permission that is the union of the current permission and the specified permission.
C# Syntax:
IPermission Union(
   IPermission target
);
Parameters:

target

A permission to combine with the current permission. It must be of the same type as the current permission.

Return Value:
A new permission that represents the union of the current permission and the specified permission.
Exceptions
Exception Type Condition
ArgumentException The target parameter is not of the same type as the current permission object.
Remarks
The result of a call to IPermission.Union is a permission that represents all the operations represented by both the current permission and the specified permission. Any demand that passes either permission passes their union.

The following statements are required to be true for all implementations of the IPermission.Union method.X and Y represent IPermission objects that are not null.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.