InfiniteTimeSpanConverter Class
Assembly: System.Configuration (in system.configuration.dll)
'Declaration Public NotInheritable Class InfiniteTimeSpanConverter Inherits ConfigurationConverterBase 'Usage Dim instance As InfiniteTimeSpanConverter
public final class InfiniteTimeSpanConverter extends ConfigurationConverterBase
public final class InfiniteTimeSpanConverter extends ConfigurationConverterBase
Not applicable.
This type, like all the other configuration converter types, converts strings found in the configuration file to and from the related strongly typed properties.
In particular the InfiniteTimeSpanConverter converts the String value "infinite" assigned to a configuration property to the standard infinite TimeSpan and vice versa. The infinite TimeSpan value is represented by the MaxValue enumeration value.
This converter is used with TimeSpan properties. An infinite value is persisted as the "infinite" string.
The following code example shows how to define a custom section property that uses the InfiniteTimeSpanConverter class.
For the complete example code that implements the custom section, refer to the ConfigurationConverterBase class.
<ConfigurationProperty("timeDelay", _ DefaultValue:="infinite"), _ TypeConverter(GetType(InfiniteTimeSpanConverter))> _ Public Property TimeDelay() As TimeSpan Get Return CType(Me("timeDelay"), TimeSpan) End Get Set(ByVal value As TimeSpan) Me("timeDelay") = Value End Set End Property
The following example code shows how to access the previous custom section property.
Imports System Imports System.IO Imports System.ComponentModel Imports System.Configuration NotInheritable Public Class UsingInfiniteTimeSpanConverter Public Shared Sub GetTimeDelay() Try Dim section As CustomSection = _ ConfigurationManager.GetSection( _ "CustomSection") Console.WriteLine("timeDelay: {0}", _ section.TimeDelay.ToString()) Catch e As System.Exception Console.WriteLine(e.Message) End Try End Sub 'GetTimeDelay Public Shared Sub SetTimeDelay() Try Dim config _ As System.Configuration.Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) Dim section As CustomSection = _ config.Sections.Get("CustomSection") Dim td As New TimeSpan() td = _ TimeSpan.FromMinutes( _ DateTime.Now.Minute) section.TimeDelay = td section.SectionInformation.ForceSave = True config.Save(ConfigurationSaveMode.Full) config.Save() Console.WriteLine("timeDelay: {0}", _ section.TimeDelay.ToString()) Catch e As System.Exception Console.WriteLine(e.Message) End Try End Sub 'SetTimeDelay End Class 'UsingInfiniteTimeSpanConverter
The following is a configuration excerpt as used by the previous example.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="CustomSection"
type="Samples.AspNet.CustomSection,
ConfigurationConverters,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"
allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication"
restartOnExternalChanges="true" />
</configSections>
<CustomSection fileName="default.txt" maxIdleTime="90" timeDelay="infinite"/>
</configuration>
System.ComponentModel.TypeConverter
System.Configuration.ConfigurationConverterBase
System.Configuration.InfiniteTimeSpanConverter
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.