Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ReflectionPermissionFlag Enumeration
Collapse the table of content
Expand the table of content

ReflectionPermissionFlag Enumeration

Specifies the permitted use of System.Reflection on members that are not visible.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

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

public enum ReflectionPermissionFlag
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute FlagsAttribute() */ 
public enum ReflectionPermissionFlag
public enum ReflectionPermissionFlag

 Member nameDescription
AllFlagsTypeInformation, MemberAccess, and ReflectionEmit are set. 
MemberAccessInvocation of operations on all type members is allowed. If this flag is not set, only invocation of operations on visible type members is allowed. 
NoFlagsNo reflection is allowed on types that are not visible. 
ReflectionEmitUse of System.Reflection.Emit is allowed. 
TypeInformationReflection is allowed on members of a type that are not visible. 

This enumeration is used by ReflectionPermission. If no ReflectionPermission is granted, reflection is allowed only on visible members.

Caution noteCaution

Because ReflectionPermission can provide access to private class members and metadata, it is recommended that ReflectionPermission not be granted to Internet code.

using System;
using System.Security;
using System.Security.Permissions;

public class ReflectionGenerator

    private ReflectionPermissionFlag[] myReflection =

    private int reflectionIndex = 0;

    public ReflectionGenerator()

    public void ResetIndex()
        reflectionIndex = 0;
    // CreateReflection creates a ReflectionPermission object.
    public bool CreateReflection(out ReflectionPermission reflectionPerm,
        out ReflectionPermissionFlag reflection)

        if(reflectionIndex >= myReflection.Length)
            reflectionPerm = new ReflectionPermission(PermissionState.None);
            return false;
        reflection = myReflection[reflectionIndex++];
            reflectionPerm = new ReflectionPermission(reflection);
            return true;
        catch(Exception e)
            Console.WriteLine("Cannot create ReflectionPermission: " + reflection +" "+e);
            reflectionPerm = new ReflectionPermission(PermissionState.None);
            return true;
} // End of ReflectionGenerator.

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

© 2015 Microsoft