InfiniteTimeSpanConverter クラス

定義

文字列と標準の無限 TimeSpan 値の間で変換します。

public ref class InfiniteTimeSpanConverter sealed : System::Configuration::ConfigurationConverterBase
public sealed class InfiniteTimeSpanConverter : System.Configuration.ConfigurationConverterBase
type InfiniteTimeSpanConverter = class
    inherit ConfigurationConverterBase
Public NotInheritable Class InfiniteTimeSpanConverter
Inherits ConfigurationConverterBase
継承
InfiniteTimeSpanConverter

次のコード例は、 InfiniteTimeSpanConverter クラスを使用するカスタム セクション プロパティを定義する方法を示しています。

カスタム セクションを実装する完全なコード例については、 ConfigurationConverterBase クラスを参照してください。

[ConfigurationProperty("timeDelay", 
    DefaultValue = "infinite")]
[TypeConverter(typeof(InfiniteTimeSpanConverter))]
public TimeSpan TimeDelay
{
    get
    {
        return (TimeSpan)this["timeDelay"];
    }
    set
    {
        this["timeDelay"] = value;
    }
}

<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

次のコード例は、前のカスタム セクション プロパティにアクセスする方法を示しています。

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);
            }
        }
    }
}
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
    
    
    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
End Class

前の例で使用した構成の抜粋を次に示します。

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

注釈

この型は、他のすべての構成コンバーター型と同様に、構成ファイルで見つかった文字列を、関連する厳密に型指定されたプロパティとの間で変換します。

特に、 InfiniteTimeSpanConverter は、構成プロパティに割り当てられた String 値 "infinite" を標準の無限 TimeSpan に変換します。その逆も同様です。 無限 TimeSpan 値は、 MaxValue 列挙値によって表されます。

このコンバーターは、 TimeSpan プロパティと共に使用されます。 無限の値は、"無限" 文字列として保持されます。

コンストラクター

名前 説明
InfiniteTimeSpanConverter()

InfiniteTimeSpanConverter クラスの新しいインスタンスを初期化します。

メソッド

名前 説明
CanConvertFrom(ITypeDescriptorContext, Type)

変換を許可するかどうかを決定します。

(継承元 ConfigurationConverterBase)
CanConvertFrom(Type)

このコンバーターが、指定された型のオブジェクトをこのコンバーターの型に変換できるかどうかを返します。

(継承元 TypeConverter)
CanConvertTo(ITypeDescriptorContext, Type)

変換を許可するかどうかを決定します。

(継承元 ConfigurationConverterBase)
CanConvertTo(Type)

このコンバーターがオブジェクトを指定した型に変換できるかどうかを返します。

(継承元 TypeConverter)
ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

StringTimeSpanに変換します。

ConvertFrom(Object)

指定された値をこのコンバーターの型に変換します。

(継承元 TypeConverter)
ConvertFromInvariantString(ITypeDescriptorContext, String)

インバリアント カルチャと指定したコンテキストを使用して、指定された文字列をこのコンバーターの型に変換します。

(継承元 TypeConverter)
ConvertFromInvariantString(String)

インバリアント カルチャを使用して、指定された文字列をこのコンバーターの型に変換します。

(継承元 TypeConverter)
ConvertFromString(ITypeDescriptorContext, CultureInfo, String)

指定したコンテキストとカルチャ情報を使用して、指定されたテキストをオブジェクトに変換します。

(継承元 TypeConverter)
ConvertFromString(ITypeDescriptorContext, String)

指定したコンテキストを使用して、指定されたテキストをオブジェクトに変換します。

(継承元 TypeConverter)
ConvertFromString(String)

指定したテキストをオブジェクトに変換します。

(継承元 TypeConverter)
ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

TimeSpanStringに変換します。

ConvertTo(Object, Type)

引数を使用して、指定した値オブジェクトを指定した型に変換します。

(継承元 TypeConverter)
ConvertToInvariantString(ITypeDescriptorContext, Object)

指定したコンテキストを使用して、指定した値をカルチャに依存しない文字列表現に変換します。

(継承元 TypeConverter)
ConvertToInvariantString(Object)

指定した値をカルチャに依存しない文字列表現に変換します。

(継承元 TypeConverter)
ConvertToString(ITypeDescriptorContext, CultureInfo, Object)

指定したコンテキストとカルチャ情報を使用して、指定された値を文字列形式に変換します。

(継承元 TypeConverter)
ConvertToString(ITypeDescriptorContext, Object)

指定されたコンテキストを使用して、指定された値を文字列形式に変換します。

(継承元 TypeConverter)
ConvertToString(Object)

指定した値を文字列形式に変換します。

(継承元 TypeConverter)
CreateInstance(IDictionary)

オブジェクトのプロパティ値のセットを指定して、 Object を再作成します。

(継承元 TypeConverter)
CreateInstance(ITypeDescriptorContext, IDictionary)

オブジェクトのプロパティ値のセットを指定すると、指定したコンテキストを使用して、この TypeConverter が関連付けられている型のインスタンスを作成します。

(継承元 TypeConverter)
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetConvertFromException(Object)

変換を実行できない場合にスローする例外を返します。

(継承元 TypeConverter)
GetConvertToException(Object, Type)

変換を実行できない場合にスローする例外を返します。

(継承元 TypeConverter)
GetCreateInstanceSupported()

このオブジェクトの値を変更するには、新しい値を作成するために CreateInstance(IDictionary) メソッドの呼び出しが必要かどうかを返します。

(継承元 TypeConverter)
GetCreateInstanceSupported(ITypeDescriptorContext)

このオブジェクトの値を変更するために、指定したコンテキストを使用して新しい値を作成するために CreateInstance(IDictionary) の呼び出しが必要かどうかを返します。

(継承元 TypeConverter)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetProperties(ITypeDescriptorContext, Object, Attribute[])

指定したコンテキストと属性を使用して、値パラメーターで指定された配列の型のプロパティのコレクションを返します。

(継承元 TypeConverter)
GetProperties(ITypeDescriptorContext, Object)

指定したコンテキストを使用して、値パラメーターで指定された配列の型のプロパティのコレクションを返します。

(継承元 TypeConverter)
GetProperties(Object)

value パラメーターで指定された配列の型のプロパティのコレクションを返します。

(継承元 TypeConverter)
GetPropertiesSupported()

このオブジェクトがプロパティをサポートしているかどうかを返します。

(継承元 TypeConverter)
GetPropertiesSupported(ITypeDescriptorContext)

指定したコンテキストを使用して、このオブジェクトがプロパティをサポートするかどうかを返します。

(継承元 TypeConverter)
GetStandardValues()

この型コンバーターが設計されているデータ型の既定のコンテキストから標準値のコレクションを返します。

(継承元 TypeConverter)
GetStandardValues(ITypeDescriptorContext)

この型コンバーターがフォーマット コンテキストで指定された場合に設計されたデータ型の標準値のコレクションを返します。

(継承元 TypeConverter)
GetStandardValuesExclusive()

GetStandardValues()から返される標準値のコレクションが排他的リストであるかどうかを返します。

(継承元 TypeConverter)
GetStandardValuesExclusive(ITypeDescriptorContext)

指定したコンテキストを使用して、 GetStandardValues() から返される標準値のコレクションが使用可能な値の排他的リストであるかどうかを返します。

(継承元 TypeConverter)
GetStandardValuesSupported()

このオブジェクトが、リストから選択できる標準の値セットをサポートしているかどうかを返します。

(継承元 TypeConverter)
GetStandardValuesSupported(ITypeDescriptorContext)

このオブジェクトが、指定したコンテキストを使用してリストから選択できる標準の値セットをサポートしているかどうかを返します。

(継承元 TypeConverter)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsValid(ITypeDescriptorContext, Object)

指定した値オブジェクトがこの型と指定したコンテキストに対して有効かどうかを返します。

(継承元 TypeConverter)
IsValid(Object)

指定された値オブジェクトがこの型に対して有効かどうかを返します。

(継承元 TypeConverter)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
SortProperties(PropertyDescriptorCollection, String[])

プロパティのコレクションを並べ替えます。

(継承元 TypeConverter)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください