InfiniteTimeSpanConverter クラス
アセンブリ: System.Configuration (system.configuration.dll 内)


この型は、他のすべての構成コンバータ型と同様に、構成ファイル内に存在する文字列と、関連する厳密に型指定されたプロパティとの間の変換を行います。
特に、InfiniteTimeSpanConverter は、構成プロパティに代入された String 値 "infinite" から標準の無限 TimeSpan への変換、およびその逆の変換を行います。無限の TimeSpan 値は、MaxValue 列挙値によって表されます。
このコンバータは、TimeSpan プロパティと共に使用されます。無限値は、"infinite" 文字列として永続化されます。

InfiniteTimeSpanConverter クラスを使用したカスタム セクション プロパティを定義する方法を次のコード例に示します。
カスタム セクションを実装する完全なコード例については、ConfigurationConverterBase クラスを参照してください。
<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
[ConfigurationProperty("timeDelay", DefaultValue = "infinite")] [TypeConverter(typeof(InfiniteTimeSpanConverter))] public TimeSpan TimeDelay { get { return (TimeSpan)this["timeDelay"]; } set { this["timeDelay"] = value; } }
前述のカスタム セクション プロパティへのアクセス方法を次のコード例に示します。
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
using System; using System.IO; using System.ComponentModel; using System.Configuration; namespace Samples.AspNet { public sealed class UsingInfiniteTimeSpanConverter { public static void GetTimeDelay() { try { CustomSection section = ConfigurationManager.GetSection("CustomSection") as CustomSection; Console.WriteLine("timeDelay: {0}", section.TimeDelay.ToString()); } catch (System.Exception e) { Console.WriteLine(e.Message); } } public static void SetTimeDelay() { try { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); CustomSection section = config.Sections.Get("CustomSection") as CustomSection; TimeSpan td = 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 (System.Exception e) { Console.WriteLine(e.Message); } } } }
<?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 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- InfiniteTimeSpanConverter クラスのページへのリンク