StrongNameIdentityPermission.FromXml(SecurityElement) 方法

定義

透過 XML 編碼,重新建構具有指定狀態的權限。

public:
 override void FromXml(System::Security::SecurityElement ^ e);
public override void FromXml (System.Security.SecurityElement e);
override this.FromXml : System.Security.SecurityElement -> unit
Public Overrides Sub FromXml (e As SecurityElement)

參數

e
SecurityElement

用來重新建構權限的 XML 編碼。

例外狀況

e 參數為 null

e 參數不是有效的權限項目。

-或-

e 參數的版本號碼無效。

範例

下列程式碼範例顯示 方法的行為 FromXml 。 此範例是針對 類別提供的較大範例的 StrongNameIdentityPermission 一部分。 此範例的最佳用法是建置和執行整個範例,並檢視其輸出。

注意

程式碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。

    // ToXml creates an XML encoding of the permission and its current state;
    //FromXml reconstructs a permission with the specified state from the XML encoding.
    bool ToFromXmlDemo()
    {
        bool returnValue = true;
        StrongNameIdentityPermission^ snIdPerm1;
        StrongNameIdentityPermission^ snIdPerm2;
        snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", gcnew Version("1.0.0.0"));    
        snIdPerm2 = gcnew StrongNameIdentityPermission(PermissionState::None);
        snIdPerm2->FromXml(snIdPerm1->ToXml());
        Console::WriteLine("Result of ToFromXml = " + snIdPerm2->ToString() + "\n");

        return returnValue;
    }


public:
// ToXml creates an XML encoding of the permission and its current state;
//FromXml reconstructs a permission with the specified state from the XML encoding.
private bool ToFromXmlDemo()
{

    bool returnValue = true;

    StrongNameIdentityPermission snIdPerm1, snIdPerm2;

    snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));    
    snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);
    snIdPerm2.FromXml(snIdPerm1.ToXml());
    Console.WriteLine("Result of ToFromXml = " + snIdPerm2.ToString() + "\n");

    return returnValue;
}
' ToXml creates an XML encoding of the permission and its current state;
'FromXml reconstructs a permission with the specified state from the XML encoding.
Private Function ToFromXmlDemo() As Boolean 
    
    Dim returnValue As Boolean = True
    
    Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
    
    snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", New Version("1.0.0.0"))
    snIdPerm2 = New StrongNameIdentityPermission(PermissionState.None)
    snIdPerm2.FromXml(snIdPerm1.ToXml())
    Console.WriteLine("Result of ToFromXml = " + snIdPerm2.ToString() + vbLf)
    
    Return returnValue

End Function 'ToFromXmlDemo

備註

應用程式程式碼不會使用這個方法。

適用於