Export (0) Print
Expand All

StrongNameIdentityPermission Constructor

.NET Framework 1.1

Initializes a new instance of the StrongNameIdentityPermission class.

Overload List

Initializes a new instance of the StrongNameIdentityPermission class with fully restricted PermissionState.

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

Initializes a new instance of the StrongNameIdentityPermission class for the specified strong name identity.

[Visual Basic] Public Sub New(StrongNamePublicKeyBlob, String, Version)
[C#] public StrongNameIdentityPermission(StrongNamePublicKeyBlob, string, Version);
[C++] public: StrongNameIdentityPermission(StrongNamePublicKeyBlob*, String*, Version*);
[JScript] public function StrongNameIdentityPermission(StrongNamePublicKeyBlob, String, Version);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the StrongNameIdentityPermission constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' This class generates StrongNameIdentityPermission objects.

Friend Class SnGenerator


    Private mySn As String() = {"MyCompany.MyDepartment.MyFile", "MyCompany.MyDepartment.*", "*"}

    Private SnIndex As Integer = 0


    Public Sub New()
        ResetIndex()
    End Sub 'New


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


    Public Function CreateSn(ByRef SnPerm As StrongNameIdentityPermission, ByRef Sn As String) As Boolean
        ' Public key
        Dim b1 As Byte() = {0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34, 97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 151, 178, 0, 230, 152, 218, 8, 206, 206, 170, 84, 111, 145, 26, 208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111, 224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101, 193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104, 252, 87, 109, 190, 56, 34, 180}

        Dim blob As New StrongNamePublicKeyBlob(b1)
        ' Use this version number.
        Dim v1 As New Version("1.0.0.0")

        If SnIndex = mySn.Length Then
            SnPerm = New StrongNameIdentityPermission(PermissionState.None)
            Sn = ""
            SnIndex += 1
            Return True
        End If
        If SnIndex > mySn.Length Then
            SnPerm = Nothing
            Sn = ""
            Return False
        End If

        Sn = mySn(SnIndex)
        SnIndex = SnIndex + 1

        Try
            SnPerm = New StrongNameIdentityPermission(blob, Sn, v1)

            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create StrongNameIdentityPermission: " + Sn + " " + e.ToString()))
            SnPerm = New StrongNameIdentityPermission(PermissionState.None)
            Sn = ""
            Return True
        End Try
    End Function 'CreateSn 
End Class 'SnGenerator


' End of SnGenerator.

[C#] 
// This class generates StrongNameIdentityPermission objects.
 internal  class SnGenerator
{


    private string[] mySn = 
    {"MyCompany.MyDepartment.MyFile","MyCompany.MyDepartment.*", "*"};

    private int snIndex = 0;

    public SnGenerator()
    {
        ResetIndex();
    }

    public void ResetIndex()
    {
        snIndex = 0;
    }

    public bool CreateSn(out StrongNameIdentityPermission snPerm, out string strongName)
    {
        // Public key
        byte[] b1 = { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0,
                        82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34, 
                        97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 
                        151, 178, 0, 230, 152, 218, 8, 206, 206, 170,84, 111, 145, 26, 
                        208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111, 
                        224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 
                        32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 
                        175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92, 
                        42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101, 
                        193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104,
                        252, 87, 109, 190, 56, 34, 180};

        StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);
        // Use this version number.
        Version v1 = new Version("1.0.0.0");

        if(snIndex == mySn.Length) 
        {
            snPerm = new StrongNameIdentityPermission(PermissionState.None);
            strongName="";
            snIndex++;
            return true;

        }
        if(snIndex > mySn.Length) 
        {
            snPerm = null;
            strongName = "";
            return false;
        }

        strongName = mySn[snIndex++];

        try
        {
            snPerm = new StrongNameIdentityPermission(blob, strongName, v1);

            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create StrongNameIdentityPermission: " + strongName +" "+e);
            snPerm = new StrongNameIdentityPermission(PermissionState.None);
            strongName="";
            return true;
        }

    }


} // End of SnGenerator.

[C++] 
// This class generates StrongNameIdentityPermission objects.
private __gc class SnGenerator {
private:
   String* mySn[];
   int  snIndex;

public:
   SnGenerator() {
      String* temp[] = {
         S"MyCompany.MyDepartment.MyFile",
         S"MyCompany.MyDepartment.*",
         S"*"};
      mySn = temp;
      ResetIndex();
   }

   void ResetIndex() {
      snIndex = 0;
   }

   bool CreateSn([Out] StrongNameIdentityPermission** snPerm, [Out] String** strongName) {
      // Public key
      Byte b1[] = { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0,
         82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34,
         97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7,
         151, 178, 0, 230, 152, 218, 8, 206, 206, 170, 84, 111, 145, 26,
         208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111,
         224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157,
         32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247,
         175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92,
         42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101,
         193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104,
         252, 87, 109, 190, 56, 34, 180};

      StrongNamePublicKeyBlob* blob = new StrongNamePublicKeyBlob(b1);
      // Use this version number.
      Version* v1 = new Version(S"1.0.0.0");

      if (snIndex == mySn->Length) {
         *snPerm = new StrongNameIdentityPermission(PermissionState::None);
         *strongName=S"";
         snIndex++;
         return true;
      }
      if (snIndex > mySn->Length) {
         *snPerm = 0;
         *strongName = S"";
         return false;
      }

      *strongName = mySn[snIndex++];

      try {
         *snPerm = new StrongNameIdentityPermission(blob, *strongName, v1);
         return true;
      } catch (Exception* e) {
         Console::WriteLine(S"Cannot create StrongNameIdentityPermission: {0} {1}", *strongName, e);
         *snPerm = new StrongNameIdentityPermission(PermissionState::None);
         *strongName=S"";
         return true;
      }
   }
}; // End of SnGenerator.

[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

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

Show:
© 2014 Microsoft