Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum ReflectionPermissionFlag
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute FlagsAttribute() */ 
public enum ReflectionPermissionFlag
SerializableAttribute 
ComVisibleAttribute(true) 
FlagsAttribute 
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 =
{
    ReflectionPermissionFlag.AllFlags,
    ReflectionPermissionFlag.MemberAccess,
    ReflectionPermissionFlag.NoFlags,
    ReflectionPermissionFlag.ReflectionEmit,
    ReflectionPermissionFlag.TypeInformation
};

    private int reflectionIndex = 0;

    public ReflectionGenerator()
    {
        ResetIndex();
    }

    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);
            reflection=ReflectionPermissionFlag.NoFlags;
            reflectionIndex++;
            return false;
        }
        reflection = myReflection[reflectionIndex++];
        try
        {
            reflectionPerm = new ReflectionPermission(reflection);
            return true;
        }
        catch(Exception e)
        {
            Console.WriteLine("Cannot create ReflectionPermission: " + reflection +" "+e);
            reflectionPerm = new ReflectionPermission(PermissionState.None);
            reflection=ReflectionPermissionFlag.NoFlags;
            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

Show:
© 2014 Microsoft