本文整理汇总了VB.NET中System.Configuration.ConfigurationProperty类的典型用法代码示例。如果您正苦于以下问题:VB.NET ConfigurationProperty类的具体用法?VB.NET ConfigurationProperty怎么用?VB.NET ConfigurationProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigurationProperty类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: New
' 导入命名空间
Imports System.Configuration
Imports System.Collections
Imports System.ComponentModel
' Define a custom section.
' Shows how to use the ConfigurationProperty
' class when defining a custom section.
Public NotInheritable Class CustomSection
Inherits ConfigurationSection
' The collection (property bag) that contains
' the section properties.
Private Shared _Properties As ConfigurationPropertyCollection
' The FileName property.
Private Shared _FileName As ConfigurationProperty
' The Alias property.
Private Shared _Alias As ConfigurationProperty
' The MasUsers property.
Private Shared _MaxUsers As ConfigurationProperty
' The MaxIdleTime property.
Private Shared _MaxIdleTime As ConfigurationProperty
' CustomSection constructor.
Shared Sub New()
' Initialize the _FileName property
_FileName = New ConfigurationProperty( _
"fileName", GetType(String), "default.txt")
' Initialize the _MaxUsers property
_MaxUsers = New ConfigurationProperty( _
"maxUsers", GetType(Long), 1000L, _
ConfigurationPropertyOptions.None)
' Initialize the _MaxIdleTime property
Dim minTime As TimeSpan = TimeSpan.FromSeconds(30)
Dim maxTime As TimeSpan = TimeSpan.FromMinutes(5)
Dim _TimeSpanValidator = _
New TimeSpanValidator(minTime, maxTime, False)
_MaxIdleTime = New ConfigurationProperty( _
"maxIdleTime", GetType(TimeSpan), _
TimeSpan.FromMinutes(5), _
TypeDescriptor.GetConverter(GetType(TimeSpan)), _
_TimeSpanValidator, _
ConfigurationPropertyOptions.IsRequired, _
"[Description:This is the max idle time.]")
' Initialize the _Alias property
_Alias = New ConfigurationProperty( _
"alias", GetType(String), "alias.txt")
' Property collection initialization.
' The collection (property bag) that contains
' the properties is declared as:
' ConfigurationPropertyCollection _Properties;
_Properties = New ConfigurationPropertyCollection()
_Properties.Add(_FileName)
_Properties.Add(_Alias)
_Properties.Add(_MaxUsers)
_Properties.Add(_MaxIdleTime)
End Sub
' Return the initialized property bag
' for the configuration element.
Protected Overrides ReadOnly Property Properties() _
As ConfigurationPropertyCollection
Get
Return _Properties
End Get
End Property
<StringValidator(InvalidCharacters:= _
" ~!@#$%^&*()[]{}/;'""|\", MinLength:=1, _
MaxLength:=60)> _
Public Property FileName() As String
Get
Return CStr(Me("fileName"))
End Get
Set(ByVal value As String)
Me("fileName") = value
End Set
End Property
<StringValidator(InvalidCharacters:= _
" ~!@#$%^&*()[]{}/;'""|\", MinLength:=1, _
MaxLength:=60)> _
Public Property [Alias]() As String
Get
Return CStr(Me("alias"))
End Get
Set(ByVal value As String)
Me("alias") = value
End Set
End Property
<LongValidator(MinValue:=1, _
MaxValue:=1000000, ExcludeRange:=False)> _
Public Property MaxUsers() As Long
Get
Return Fix(Me("maxUsers"))
End Get
Set(ByVal value As Long)
Me("maxUsers") = value
End Set
End Property
Public Property MaxIdleTime() As TimeSpan
Get
Return CType(Me("maxIdleTime"), TimeSpan)
End Get
Set(ByVal value As TimeSpan)
Me("maxIdleTime") = value
End Set
End Property
End Class
开发者ID:VB.NET开发者,项目名称:System.Configuration,代码行数:122,代码来源:ConfigurationProperty
示例2: CreateSection
' Create a custom section.
Shared Sub CreateSection()
Try
Dim customSection As CustomSection
' Get the current configuration file.
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Create the section entry
' in the <configSections> and the
' related target section in <configuration>.
' Since the config file already has "CustomSection",
' call this one "CustomSection2".
If config.Sections("CustomSection") Is Nothing Then
customSection = New CustomSection()
config.Sections.Add("CustomSection", customSection)
customSection.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
End If
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
开发者ID:VB.NET开发者,项目名称:System.Configuration,代码行数:25,代码来源:ConfigurationProperty
注:本文中的System.Configuration.ConfigurationProperty类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论