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

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

INameCreationService.CreateName メソッド

指定したコンテナ内でどのコンポーネントとも重複しない新しい名前を作成します

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

Function CreateName ( _
    container As IContainer, _
    dataType As Type _
) As String
Dim instance As INameCreationService
Dim container As IContainer
Dim dataType As Type
Dim returnValue As String

returnValue = instance.CreateName(container, dataType)
string CreateName (
    IContainer container,
    Type dataType
)
String^ CreateName (
    IContainer^ container, 
    Type^ dataType
)
String CreateName (
    IContainer container, 
    Type dataType
)
function CreateName (
    container : IContainer, 
    dataType : Type
) : String

パラメータ

container

新しオブジェクト追加される先のコンテナ

dataType

名前を受け取オブジェクトデータ型

戻り値
データ型一意の名前。

解説解説

このメソッドは、指定したコンテナ内で重複しない新しオブジェクトの名前を返します

実装時の注意 この種類サービスは、データ型の名前から一意オブジェクト名を作成するために実装されることがあります。これには、名前を一意識別子にするための番号追加される場合あります。たとえば、ListBox オブジェクトでは ListBox1 のようになります

使用例使用例

INameCreationService.CreateName メソッド実装するコード例次に示します。このメソッドでは、指定したコンテナ内のコンポーネントに対して一意な名前を、指定した種類作成できます

' Creates an identifier for a particular data type that does not conflict
 
' with the identifiers of any components in the specified collection
Public Function CreateName(ByVal
 container As System.ComponentModel.IContainer, ByVal
 dataType As System.Type) As String Implements INameCreationService.CreateName
    ' Create a basic type name string
    Dim baseName As String
 = dataType.Name
    Dim uniqueID As Integer
 = 1

    Dim unique As Boolean
 = False
    ' Continue to increment uniqueID numeral until a unique ID is located.
    While Not unique
        unique = True
        ' Check each component in the container for a matching 
        ' base type name and unique ID.
        Dim i As Integer
        For i = 0 To container.Components.Count
 - 1
            ' Check component name for match with unique ID string.
            If container.Components(i).Site.Name.StartsWith((baseName
 + uniqueID.ToString())) Then
                ' If a match is encountered, set flag to recycle 
                ' collection, increment ID numeral, and restart.
                unique = False
                uniqueID += 1
                Exit For
            End If
        Next i
    End While

    Return baseName + uniqueID.ToString()
End Function
// Creates an identifier for a particular data type that does not conflict
 
// with the identifiers of any components in the specified collection.
public string CreateName(System.ComponentModel.IContainer
 container, System.Type dataType)
{
    // Create a basic type name string.
    string baseName = dataType.Name;
    int uniqueID = 1;

    bool unique = false;            
    // Continue to increment uniqueID numeral until a 
    // unique ID is located.
    while( !unique )
    {
        unique = true;
        // Check each component in the container for a matching 
        // base type name and unique ID.
        for(int i=0; i<container.Components.Count;
 i++)
        {
            // Check component name for match with unique ID string.
            if( container.Components[i].Site.Name.StartsWith(baseName+uniqueID.ToString())
 )
            {
                // If a match is encountered, set flag to recycle 
                // collection, increment ID numeral, and restart.
                unique = false;
                uniqueID++;
                break;
            }
        }
    }
    
    return baseName+uniqueID.ToString();
}
// Creates an identifier for a particular data type that does not conflict
 
// with the identifiers of any components in the specified collection.
virtual String^ CreateName( System::ComponentModel::IContainer^ container, System::Type^
 dataType )
{
   // Create a basic type name string.
   String^ baseName = dataType->Name;
   int uniqueID = 1;
   bool unique = false;

   // Continue to increment uniqueID numeral until a 
   // unique ID is located.
   while (  !unique )
   {
      unique = true;

      // Check each component in the container for a matching 
      // base type name and unique ID.
      for ( int i = 0; i < container->Components->Count;
 i++ )
      {
         // Check component name for match with unique ID string.
         if ( container->Components[ i ]->Site->Name->StartsWith(
 String::Concat( baseName, uniqueID ) ) )
         {
            // If a match is encountered, set flag to recycle 
            // collection, increment ID numeral, and restart.
            unique = false;
            uniqueID++;
            break;
         }
      }
   }

   return String::Concat( baseName, uniqueID );
}
// Creates an identifier for a particular data type that does not conflict
 
// with the identifiers of any components in the specified collection.
public String CreateName(System.ComponentModel.IContainer container,
 
    System.Type dataType)
{
    // Create a basic type name string.
    String baseName = dataType.get_Name();
    int uniqueID = 1;
    boolean unique = false;

    // Continue to increment uniqueID numeral until a 
    // unique ID is located.
    while (!(unique)) {
        unique = true;

        // Check each component in the container for a matching 
        // base type name and unique ID.
        for (int i = 0; i < container.get_Components().get_Count();
 i++) {
            // Check component name for match with unique ID string.
            if (container.get_Components().get_Item(i).get_Site().
                get_Name().StartsWith((baseName + ((Int32)uniqueID).
                ToString()))) {
                // If a match is encountered, set flag to recycle 
                // collection, increment ID numeral, and restart.
                unique = false;
                uniqueID++;
                break;
            }
        }
    }
    return (baseName + ((Int32)uniqueID).ToString());
} //CreateName
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
INameCreationService インターフェイス
INameCreationService メンバ
System.ComponentModel.Design.Serialization 名前空間


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS