IdnMapping.UseStd3AsciiRules 屬性

定義

取得或設定值,指出目前 IdnMapping 物件成員執行的作業中是否使用標準或寬鬆命名慣例。

public:
 property bool UseStd3AsciiRules { bool get(); void set(bool value); };
public bool UseStd3AsciiRules { get; set; }
member this.UseStd3AsciiRules : bool with get, set
Public Property UseStd3AsciiRules As Boolean

屬性值

如果作業中使用標準命名慣例,則為 true,否則為 false

範例

下列範例會產生 URL,其中包含 ASCII 範圍中從 U+0000 到 U+007F 的字元,並將其傳遞至 GetAscii(String)IdnMapping 個 物件的 方法。 其中一個 物件的 UseStd3AsciiRules 屬性設定為 true,而另一個 物件則將其設定為 false。 輸出會顯示屬性為 但 UseStd3AsciiRules 當 屬性為 true 時無效 false的字元。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      int nFailed = 0;
      IdnMapping idnStd = new IdnMapping();
      idnStd.UseStd3AsciiRules = true;

      IdnMapping idnRelaxed = new IdnMapping();
      idnRelaxed.UseStd3AsciiRules = false;  // The default, but make it explicit.

      for (int ctr = 0; ctr <= 0x7F; ctr++) {
         string name = $"Prose{ctr}ware.com";

         bool stdFailed = false;
         bool relaxedFailed = false;
         string punyCode = "";
         try {
            punyCode = idnStd.GetAscii(name);
         }
         catch (ArgumentException) {
            stdFailed = true;
         }

         try {
            punyCode = idnRelaxed.GetAscii(name);
         }
         catch (ArgumentException) {
            relaxedFailed = true;
         }

         if (relaxedFailed != stdFailed) {
            Console.Write("U+{0:X4}     ", ctr);
            nFailed++;
            if (nFailed % 5 == 0)
               Console.WriteLine();
         }
      }
   }
}
// The example displays the following output:
//       U+0020     U+0021     U+0022     U+0023     U+0024
//       U+0025     U+0026     U+0027     U+0028     U+0029
//       U+002A     U+002B     U+002C     U+002F     U+003A
//       U+003B     U+003C     U+003D     U+003E     U+003F
//       U+0040     U+005B     U+005C     U+005D     U+005E
//       U+005F     U+0060     U+007B     U+007C     U+007D
//       U+007E
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim nFailed As Integer = 0
      Dim idnStd As New IdnMapping()
      idnStd.UseStd3AsciiRules = True
      
      Dim idnRelaxed As New IdnMapping
      idnRelaxed.UseStd3AsciiRules = False     ' The default, but make it explicit.
      
      For ctr As Integer = 0 To &h7F 
         Dim name As String = "Prose" + ChrW(ctr) + "ware.com"
         
         Dim stdFailed As Boolean = False
         Dim relaxedFailed As Boolean = False
         Dim punyCode As String
         Try
            punyCode = idnStd.GetAscii(name)
         Catch e As ArgumentException
            stdFailed = True
         End Try       
         
         Try
            punyCode = idnRelaxed.GetAscii(name)
         Catch e As ArgumentException
            relaxedFailed = True
         End Try       
         
         If relaxedFailed <> stdFailed Then
            Console.Write("U+{0:X4}     ", ctr)
            nFailed += 1
            If nFailed Mod 5 = 0 Then Console.WriteLine()         
         End If 
      Next   
   End Sub
End Module
' The example displays the following output:
'       U+0020     U+0021     U+0022     U+0023     U+0024
'       U+0025     U+0026     U+0027     U+0028     U+0029
'       U+002A     U+002B     U+002C     U+002F     U+003A
'       U+003B     U+003C     U+003D     U+003E     U+003F
'       U+0040     U+005B     U+005C     U+005D     U+005E
'       U+005F     U+0060     U+007B     U+007C     U+007D
'       U+007E

備註

遵循標準命名規則的功能變數名稱是由US-ASCII 字元範圍中的特定字元子集所組成。 字元是字母 A 到 Z、數位 0 到 9、連字元 ( ) 字元 (U+002D) ,以及句號 (.) 字元。 字元的大小寫並不重要。 寬鬆的命名慣例允許使用更廣泛的 ASCII 字元範圍,包括空格字元 (U+0020) 、驚嘆號字元 (U+0021) ,以及下列字元 (U+005F) 。 如果 UseStd3AsciiRulestrue,則只有標準字元可以出現在 方法所傳回的標籤中 GetAscii

根據預設,屬性的值 UseStd3AsciiRulesfalse,而且標籤中允許擴充的 ASCII 字元子集。

注意

類別 IdnMapping 禁止在功能變數名稱標籤中使用不可顯示字元 U+0000 到 U+001F,以及功能變數名稱標籤中的 U+007F,而不論屬性的 UseStd3AsciiRules 設定為何。 此禁止可降低安全性攻擊的風險,例如名稱詐騙。

適用於