INameCreationServiceとは? わかりやすく解説

INameCreationService インターフェイス

オブジェクト一意の名前を生成できるサービス提供します

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

Public Interface INameCreationService
Dim instance As INameCreationService
public interface INameCreationService
public interface class INameCreationService
public interface INameCreationService
public interface INameCreationService
解説解説
使用例使用例

INameCreationService実装するコード例次に示します。このサービスでは、指定したコンテナ含まれる名前のいずれとも一致しない種類の、一意な名前を作成できますまた、指定した前文字列を検証することもできます

Imports System
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Imports System.Globalization

Public Class NameCreationService
    Implements System.ComponentModel.Design.Serialization.INameCreationService

    Public Sub New()
    End Sub

    ' 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

    ' Returns whether the specified name contains 
    ' all valid character types.
    Public Function IsValidName(ByVal
 name As String) As Boolean
 Implements INameCreationService.IsValidName
        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
                    Return False
            End Select
        Next i
        Return True
    End Function

    ' 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

End Class
using System;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Globalization;

namespace NameCreationServiceExample
{
    public class NameCreationService : System.ComponentModel.Design.Serialization.INameCreationService
    {
        public NameCreationService()
        {
        }

        // 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();
        }

        // Returns whether the specified name contains 
        // all valid character types.
        public bool IsValidName(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:
                        return false;     
           
                }
            }
            return true;        
         }

        // 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.");                
                }
            }
        }
     }
}
#using <System.dll>

using namespace System;
using namespace System::ComponentModel::Design;
using namespace System::ComponentModel::Design::Serialization;
using namespace System::Globalization;

namespace NameCreationServiceExample
{
   public ref class NameCreationService: public
 System::ComponentModel::Design::Serialization::INameCreationService
   {
   public:
      NameCreationService(){}

      // 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 );
      }

      // Returns whether the specified name contains 
      // all valid character types.
      virtual bool IsValidName( 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:
                  return false;
            }
         }
         return true;
      }

      // 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 ) );
            }
         }
      }
   };
}
package NameCreationServiceExample; 

import System.*;
import System.ComponentModel.Design.*;
import System.ComponentModel.Design.Serialization.*;
import System.Globalization.*;

public class NameCreationService 
    implements System.ComponentModel.Design.Serialization.INameCreationService
{
    public NameCreationService()
    {
    } //NameCreationService

    // 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

    // Returns whether the specified name contains 
    // all valid character types.
    public boolean IsValidName(String name)
    {
        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:
                    return false;
            }
        }
        return true;
    } //IsValidName

    // 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
} //NameCreationService 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
INameCreationService メンバ
System.ComponentModel.Design.Serialization 名前空間

INameCreationService メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド CreateName 指定したコンテナ内でどのコンポーネントとも重複しない新しい名前を作成します
パブリック メソッド IsValidName 指定した名前が有効かどうかを示す値を取得します
パブリック メソッド ValidateName 指定した名前が有効かどうかを示す値を取得します
参照参照

関連項目

INameCreationService インターフェイス
System.ComponentModel.Design.Serialization 名前空間

INameCreationService メンバ

オブジェクト一意の名前を生成できるサービス提供します

INameCreationService データ型公開されるメンバを以下の表に示します


パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド CreateName 指定したコンテナ内でどのコンポーネントとも重複しない新しい名前を作成します
パブリック メソッド IsValidName 指定した名前が有効かどうかを示す値を取得します
パブリック メソッド ValidateName 指定した名前が有効かどうかを示す値を取得します
参照参照

関連項目

INameCreationService インターフェイス
System.ComponentModel.Design.Serialization 名前空間



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

辞書ショートカット

すべての辞書の索引

「INameCreationService」の関連用語

INameCreationServiceのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS