当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET INameCreationService接口代码示例

本文整理汇总了VB.NET中System.ComponentModel.Design.Serialization.INameCreationService接口的典型用法代码示例。如果您正苦于以下问题:VB.NET INameCreationService接口的具体用法?VB.NET INameCreationService怎么用?VB.NET INameCreationService使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。


在下文中一共展示了INameCreationService接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: NameCreationService

' 导入命名空间
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
开发者ID:VB.NET开发者,项目名称:System.ComponentModel.Design.Serialization,代码行数:72,代码来源:INameCreationService


注:本文中的System.ComponentModel.Design.Serialization.INameCreationService接口示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。