當前位置: 首頁>>代碼示例>>C#>>正文


C# DnsPermission.FromXml方法代碼示例

本文整理匯總了C#中System.Net.DnsPermission.FromXml方法的典型用法代碼示例。如果您正苦於以下問題:C# DnsPermission.FromXml方法的具體用法?C# DnsPermission.FromXml怎麽用?C# DnsPermission.FromXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了DnsPermission.FromXml方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConstructDnsPermission

public void ConstructDnsPermission() {
  try 
  {
    // Create a DnsPermission instance.
    DnsPermission permission = new DnsPermission(PermissionState.None);
    // Create a SecurityElement instance by calling the ToXml method on the 
    // DnsPermission instance.
    // Print its attributes, which hold the  XML encoding of the DnsPermission
    // instance.
    Console.WriteLine("Attributes and Values of 'DnsPermission' instance :");
    PrintKeysAndValues(permission.ToXml().Attributes);

    // Create a SecurityElement instance.
    SecurityElement securityElementObj = new SecurityElement("IPermission");
    // Add attributes and values of the SecurityElement instance corresponding to
    // the permission instance. 
    securityElementObj.AddAttribute("version", "1");
    securityElementObj.AddAttribute("Unrestricted", "true");
    securityElementObj.AddAttribute("class","System.Net.DnsPermission");
                     
    // Reconstruct a DnsPermission instance from an XML encoding.
      DnsPermission permission1 = new DnsPermission(PermissionState.None);
    permission1.FromXml(securityElementObj);

    // Print the attributes and values of the constructed DnsPermission object.
    Console.WriteLine("After reconstruction Attributes and Values of new DnsPermission instance :");
    PrintKeysAndValues(permission1.ToXml().Attributes);
  }
  catch(NullReferenceException e) 
  {
    Console.WriteLine("NullReferenceException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
  catch(SecurityException e) 
  {
    Console.WriteLine("SecurityException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
  catch(ArgumentNullException e) 
  {
    Console.WriteLine("ArgumentNullException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
  catch(Exception e)
  {
    Console.WriteLine("Exception caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
  }
}

private void PrintKeysAndValues(Hashtable myList) {
   // Get the enumerator that can iterate through the hash table.
   IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
   Console.WriteLine("\t-KEY-\t-VALUE-");
   while (myEnumerator.MoveNext())
      Console.WriteLine("\t{0}:\t{1}", myEnumerator.Key, myEnumerator.Value);
      Console.WriteLine();
}
開發者ID:.NET開發者,項目名稱:System.Net,代碼行數:62,代碼來源:DnsPermission.FromXml


注:本文中的System.Net.DnsPermission.FromXml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。