Export (0) Print
Expand All

ReflectionPermission Constructor

.NET Framework 1.1

Initializes a new instance of the ReflectionPermission class.

Overload List

Initializes a new instance of the ReflectionPermission class with either fully restricted or unrestricted permission as specified.

[Visual Basic] Public Sub New(PermissionState)
[C#] public ReflectionPermission(PermissionState);
[C++] public: ReflectionPermission(PermissionState);
[JScript] public function ReflectionPermission(PermissionState);

Initializes a new instance of the ReflectionPermission class with the specified access.

[Visual Basic] Public Sub New(ReflectionPermissionFlag)
[C#] public ReflectionPermission(ReflectionPermissionFlag);
[C++] public: ReflectionPermission(ReflectionPermissionFlag);
[JScript] public function ReflectionPermission(ReflectionPermissionFlag);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the ReflectionPermission constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' 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
    Try
        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

[C#] 
// 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;
    }
}

[C++] 
// 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(S"Cannot create ReflectionPermission: {0} {1}", __box(*reflection), e);
         *reflectionPerm = new ReflectionPermission(PermissionState::None);
         *reflection=ReflectionPermissionFlag::NoFlags;
         return true;
      }
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ReflectionPermission Class | ReflectionPermission Members | System.Security.Permissions Namespace

Show:
© 2014 Microsoft