INameCreationService.ValidateName メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > INameCreationService.ValidateName メソッドの意味・解説 

INameCreationService.ValidateName メソッド

指定した名前が有効かどうかを示す値を取得します

名前空間: System.ComponentModel.Design.Serialization
アセンブリ: System (system.dll 内)
構文構文

Sub ValidateName ( _
    name As String _
)
Dim instance As INameCreationService
Dim name As String

instance.ValidateName(name)
void ValidateName (
    string name
)
void ValidateName (
    String^ name
)
void ValidateName (
    String name
)
function ValidateName (
    name : String
)

パラメータ

name

検証対象の名前。

解説解説

INameCreationService の実装は、有効な名前のパラメータ定義する規則を持つことができます。このメソッド実装して、名前を検証し上記規則適用できます

このメソッドは IsValidName に類似していますが、名前が無効である場合例外スローするという点が異なります。これにより、例外メッセージ詳細な情報指定できます

使用例使用例

次に示すのは、INameCreationService.IsValidName メソッド実装するコード例です。文字列検証スキーム使用して指定文字列の各文字確認し指定文字列有効な名前であるかどうか判定します。文字列有効でない場合、このメソッド例外スローます。

' Throws an exception if the specified name does not contain 
' all valid character types.
Public Sub ValidateName(ByVal
 name As String) Implements
 INameCreationService.ValidateName
    Dim i As Integer
    For i = 0 To name.Length - 1
        Dim ch As Char =
 name.Chars(i)
        Dim uc As UnicodeCategory = [Char].GetUnicodeCategory(ch)
        Select Case uc
            Case UnicodeCategory.UppercaseLetter, UnicodeCategory.LowercaseLetter,
 UnicodeCategory.TitlecaseLetter, UnicodeCategory.DecimalDigitNumber
            Case Else
                Throw New Exception("The
 name '" + name + "' is not a valid identifier.")
        End Select
    Next i
End Sub
// Throws an exception if the specified name does not contain 
// all valid character types.
public void ValidateName(string
 name)
{
    for(int i = 0; i < name.Length; i++)
    {
        char ch = name[i];
        UnicodeCategory uc = Char.GetUnicodeCategory(ch);
        switch (uc) 
        {
            case UnicodeCategory.UppercaseLetter:       
            case UnicodeCategory.LowercaseLetter:     
            case UnicodeCategory.TitlecaseLetter:            
                                      
            case UnicodeCategory.DecimalDigitNumber:         
                
                break;
            default:
                throw new Exception("The name '"+name+"'
 is not a valid identifier.");                
        }
    }
}
// Throws an exception if the specified name does not contain 
// all valid character types.
virtual void ValidateName( String^ name )
{
   for ( int i = 0; i < name->Length;
 i++ )
   {
      Char ch = name[ i ];
      UnicodeCategory uc = Char::GetUnicodeCategory( ch );
      switch ( uc )
      {
         case UnicodeCategory::UppercaseLetter:
         case UnicodeCategory::LowercaseLetter:
         case UnicodeCategory::TitlecaseLetter:
         case UnicodeCategory::DecimalDigitNumber:
            break;

         default:
            throw gcnew Exception( String::Format( "The name '{0}' is not a
 valid identifier.", name ) );
      }
   }
}
// Throws an exception if the specified name does not contain 
// all valid character types.
public void ValidateName(String name)throws
 java.lang.Exception
{
    for (int i = 0; i < name.length(); i++)
 {
        char ch = name.get_Chars(i);
        UnicodeCategory uc = Char.GetUnicodeCategory(ch);
        switch (uc) {
            case UnicodeCategory.UppercaseLetter:
            case UnicodeCategory.LowercaseLetter:
            case UnicodeCategory.TitlecaseLetter:
            case UnicodeCategory.DecimalDigitNumber:
                break;

            default:
                throw new Exception("The name '" + name
 
                    + "' is not a valid identifier.");
        }
    }
} //ValidateName
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
INameCreationService インターフェイス
INameCreationService メンバ
System.ComponentModel.Design.Serialization 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からINameCreationService.ValidateName メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からINameCreationService.ValidateName メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からINameCreationService.ValidateName メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「INameCreationService.ValidateName メソッド」の関連用語

INameCreationService.ValidateName メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



INameCreationService.ValidateName メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS