Lire en anglais Modifier

Partager via


ReflectionPermissionFlag Enum

Definition

Caution

Code Access Security is not supported or honored by the runtime.

Specifies the permitted use of the System.Reflection and System.Reflection.Emit namespaces.

This enumeration supports a bitwise combination of its member values.

[System.Flags]
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum ReflectionPermissionFlag
[System.Flags]
[System.Serializable]
public enum ReflectionPermissionFlag
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ReflectionPermissionFlag
[System.Flags]
public enum ReflectionPermissionFlag
Inheritance
ReflectionPermissionFlag
Attributes

Fields

Name Value Description
NoFlags 0

Enumeration of types and members is allowed. Invocation operations are allowed on visible types and members.

TypeInformation 1

This flag is obsolete. No flags are necessary to enumerate types and members and to examine their metadata. Use NoFlags instead.

MemberAccess 2

Invocation operations on all members are allowed, regardless of grant set. If this flag is not set, invocation operations are allowed only on visible members.

ReflectionEmit 4

Emitting debug symbols is allowed. Beginning with the .NET Framework 2.0 Service Pack 1, this flag is no longer required to emit code.

AllFlags 7

TypeInformation , MemberAccess, and ReflectionEmit are set. AllFlags does not include RestrictedMemberAccess.

RestrictedMemberAccess 8

Restricted member access is provided for partially trusted code. Partially trusted code can access nonpublic types and members, but only if the grant set of the partially trusted code includes all permissions in the grant set of the assembly that contains the nonpublic types and members being accessed. This flag is new in the .NET Framework 2.0 SP1.

Examples

The following example shows how to use the ReflectionPermissionFlag enumeration to initialize a new instance of the ReflectionPermission class that represents the right to perform restricted member access. This example is part of a larger example that is provided for the ReflectionPermission class.

For an example that shows how to use the RestrictedMemberAccess flag with Internet code, see Walkthrough: Emitting Code in Partial Trust Scenarios.

ReflectionPermission restrictedMemberAccessPerm = new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess);

Remarks

Attention

Code Access Security (CAS) has been deprecated across all versions of .NET Framework and .NET. Recent versions of .NET do not honor CAS annotations and produce errors if CAS-related APIs are used. Developers should seek alternative means of accomplishing security tasks.

This enumeration is used by the ReflectionPermission and ReflectionPermissionAttribute classes. If no ReflectionPermission is granted, reflection is allowed on all types and members, but invocation operations are allowed only on visible types and members. For more information, see Security Considerations for Reflection.

Attention

Because ReflectionPermission can provide access to private class members, we recommend that you grant ReflectionPermission to Internet code only with the RestrictedMemberAccess flag, and not with any other flags.

The RestrictedMemberAccess flag is introduced in the .NET Framework 2.0 SP1. To use this flag, your application should target the .NET Framework 3.5 or later.

Important

AllFlags does not include the RestrictedMemberAccess flag. To get a mask that includes all flags in this enumeration, you must use the combination of AllFlags with RestrictedMemberAccess.

Starting with the .NET Framework 2.0 SP1, the ReflectionEmit flag is no longer required to emit code, unless debug symbols are emitted. To use this feature, your application should target the .NET Framework 3.5 or later.

Starting with the .NET Framework 2.0, the TypeInformation flag is no longer required to reflect on nonpublic types and members; the flag has been marked obsolete.

Applies to

Produit Versions (Obsolète)
.NET (8 (package-provided), 9 (package-provided))
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1 (5, 6, 7, 8, 9)

See also