System.Security.Permissions.ReflectionPermission Class

public sealed class ReflectionPermission : CodeAccessPermission

Base Types

Object
  CodeAccessPermission
    ReflectionPermission

This type implements IPermission.

Assembly

mscorlib

Library

Reflection

Summary

Secures access to the metadata of non-public types and members through reflection.

Description

Code with the appropriate ReflectionPermission has access to non-public members of a type . Without ReflectionPermission , code can access only the public members of assemblies.

[Note: Without ReflectionPermission, untrusted code can perform the following operations on members of loaded assemblies:

]

ReflectionPermission instances can allow untrusted code to obtain type and member information, invoke members, and enumerate types that would otherwise be inaccessible. [Note: Because ReflectionPermission can provide access to members and information that were not intended for public access, it is recommended that ReflectionPermission be granted only to trusted code.]

The XML encoding of a ReflectionPermission instance is defined below in EBNF format. The following conventions are used:

The following meta-language symbols are used:

BuildVersion refers to the build version of the shipping CLI. This is specified as a dotted build number such as '2412.0' .

ECMAPubKeyToken ::= b77a5c561934e089

ReflectionPermissionFlag = MemberAccess | TypeInformation

Each ReflectionPermissionFlag can appear in the XML no more than once. For example, Flags=MemberAccess,MemberAccess is illegal.

The XML encoding of a ReflectionPermission instance is as follows:

ReflectionPermissionXML ::=

<IPermission

class="

System.Security.Permissions.ReflectionPermission, mscorlib,

Version=1.0. BuildVersion,

Culture=neutral,

PublicKeyToken= ECMAPubKeyToken"

version="1"

(

Unrestricted="true"

)

|

(

Flags="NoFlags | (ReflectionPermissionFlag (, ReflectionPermissionFlag)*"

)

/>

See Also

System.Security.Permissions Namespace

Members

ReflectionPermission Constructors

ReflectionPermission Constructor

ReflectionPermission Methods

ReflectionPermission.Copy Method
ReflectionPermission.FromXml Method
ReflectionPermission.Intersect Method
ReflectionPermission.IsSubsetOf Method
ReflectionPermission.ToXml Method
ReflectionPermission.Union Method


ReflectionPermission Constructor

public ReflectionPermission(ReflectionPermissionFlag flag);

Summary

Constructs and initializes a new instance of the ReflectionPermission class with the specified access.

Parameters

flag
One or more ReflectionPermissionFlag values.

Exceptions

Exception TypeCondition
ArgumentExceptionThe flag parameter contains a value that is not a combination of ReflectionPermissionFlag values.

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace

ReflectionPermission.Copy Method

public override IPermission Copy();

Summary

Returns a new ReflectionPermission object containing the same values as the current instance.

Return Value

A new ReflectionPermission instance that contains the same values as the current instance.

Description

[Note: The object returned by this method represents the same access to resources as the current instance.

This method overrides System.Security.CodeAccessPermission.Copy and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace

ReflectionPermission.FromXml Method

public override void FromXml(SecurityElement esd);

Summary

Reconstructs the state of a ReflectionPermission object using the specified XML encoding.

Parameters

esd
A SecurityElement instance containing the XML encoding to use to reconstruct the state of a ReflectionPermission object.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThe esd parameter is null .
ArgumentExceptionThe esd parameter is not a ReflectionPermission element.

-or-

The esd parameter's version number is not valid.

Description

The state of the current instance is changed to the state encoded in esd.

[Note: For the XML encoding for this class, see the ReflectionPermission class page.

This method overrides System.Security.CodeAccessPermission.FromXml(System.Security.SecurityElement) .

]

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace

ReflectionPermission.Intersect Method

public override IPermission Intersect(IPermission target);

Summary

Returns a new ReflectionPermission object that is the intersection of the current instance and the specified object.

Parameters

target
A ReflectionPermission instance to intersect with the current instance.

Return Value

A new ReflectionPermission instance that represents the intersection of the current instance and target. If the intersection is empty, returns null . If target is null , returns null .

Exceptions

Exception TypeCondition
ArgumentExceptionThe target parameter is not null and is not an instance of ReflectionPermission .

Description

[Note: The intersection of two permissions is a permission that secures the resources and operations secured by both permissions. Specifically, it represents the minimum permission such that any demand that passes both permissions will also pass their intersection.

This method overrides System.Security.CodeAccessPermission.Intersect(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace

ReflectionPermission.IsSubsetOf Method

public override bool IsSubsetOf(IPermission target);

Summary

Determines whether the current instance is a subset of the specified object.

Parameters

target
A ReflectionPermission instance that is to be tested for the subset relationship.

Return Value

true if the current instance is a subset of target ; otherwise, false . If the current instance is unrestricted, and target is not, returns false . If target is unrestricted, returns true . If target is null and the access level of the current instance is System.Security.Permissions.ReflectionPermissionFlag.NoFlags, returns true . If target is null and the access level of the current instance is any value other than System.Security.Permissions.ReflectionPermissionFlag.NoFlags, returns false .

Exceptions

Exception TypeCondition
ArgumentExceptionThe target parameter is not null and is not an instance of ReflectionPermission .

Description

[Note: The current instance is a subset of target if the current instance specifies a set of accesses to resources that is wholly contained by target . For example, a permission that represents access to type information is a subset of a permission that represents access to type information and members.

This method overrides System.Security.CodeAccessPermission.IsSubsetOf(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace

ReflectionPermission.ToXml Method

public override SecurityElement ToXml();

Summary

Returns the XML encoding of the current instance.

Return Value

A SecurityElement containing the XML encoding of the state of the current instance.

Description

[Note: For the XML encoding for this class, see the ReflectionPermission class page.

This method overrides System.Security.CodeAccessPermission.ToXml .

]

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace

ReflectionPermission.Union Method

public override IPermission Union(IPermission other);

Summary

Returns a new ReflectionPermission object that is the union of the current instance and the specified object.

Parameters

other
A ReflectionPermission instance to be combined with the current instance.

Return Value

A new ReflectionPermission instance that represents the union of the current instance and other. If the current instance or other is unrestricted, returns a ReflectionPermission instance that is unrestricted. If other is null , returns a copy of the current instance.

Exceptions

Exception TypeCondition
ArgumentExceptionThe other parameter is not null and is not an instance of ReflectionPermission .

Description

[Note: The result of a call to System.Security.Permissions.ReflectionPermission.Union(System.Security.IPermission) is a permission that represents all of the access to resources represented by both the current instance and other. Any demand that passes either the current instance or other passes their union.

This method overrides System.Security.CodeAccessPermission.Union(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.ReflectionPermission Class, System.Security.Permissions Namespace