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)

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

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

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

(継承元 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)

適用対象

こちらもご覧ください