Export (0) Print
Expand All
Expand Minimize

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 Enumeration ReflectionPermissionFlag
Dim instance As 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.

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

Public Class ReflectionGenerator

    Private myReflection As ReflectionPermissionFlag() = _
        {ReflectionPermissionFlag.AllFlags, _
         ReflectionPermissionFlag.MemberAccess, _
         ReflectionPermissionFlag.NoFlags, _
         ReflectionPermissionFlag.ReflectionEmit, _

    Private reflectionIndex As Integer = 0

    Public Sub New()
    End Sub 'New

    Public Sub ResetIndex()
        reflectionIndex = 0
    End Sub 'ResetIndex

    ' CreateReflection creates a ReflectionPermission object.
    Public Function CreateReflection(ByRef reflectionPerm As ReflectionPermission, ByRef reflection As ReflectionPermissionFlag) As Boolean

        If reflectionIndex >= myReflection.Length Then
            reflectionPerm = New ReflectionPermission(PermissionState.None)
            reflection = ReflectionPermissionFlag.NoFlags
            reflectionIndex &= 1
            Return False
        End If
        reflection = myReflection(reflectionIndex)
        reflectionIndex = reflectionIndex + 1
            reflectionPerm = New ReflectionPermission(reflection)
            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create ReflectionPermission: " & reflection & " " & e.ToString()))
            reflectionPerm = New ReflectionPermission(PermissionState.None)
            reflection = ReflectionPermissionFlag.NoFlags
            Return True
        End Try
    End Function 'CreateReflection
End Class 'ReflectionGenerator 
' 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

© 2014 Microsoft