GenericEnumConverter クラス

定義

文字列と列挙型との間の変換を行います。

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

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

using System;
using System.IO;
using System.ComponentModel;
using System.Configuration;

namespace Samples.AspNet
{
  
    public sealed class UsingGenericEnumConverter
    {
        public static void GetPermission()
        {
            try
            {
                CustomSection section =
                    ConfigurationManager.GetSection("CustomSection")
                    as CustomSection;
                
                Console.WriteLine("Default Permission: {0}", 
                    section.Permission.ToString());
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public static void SetPermission()
        {
            try
            {
                System.Configuration.Configuration config =
                  ConfigurationManager.OpenExeConfiguration(
                  ConfigurationUserLevel.None);

                CustomSection section =
                    config.Sections.Get("CustomSection")
                    as CustomSection;

                section.Permission = 
                    CustomSection.Permissions.FullControl;

                section.SectionInformation.ForceSave = true;
                config.Save(ConfigurationSaveMode.Full); 
                config.Save();

                Console.WriteLine("Current Protection: {0}",
                    section.Permission.ToString());
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
Imports System.IO
Imports System.ComponentModel
Imports System.Configuration




NotInheritable Public Class UsingGenericEnumConverter
    
    Public Shared Sub GetPermission() 
        Try
            Dim section As CustomSection = _
            ConfigurationManager.GetSection("CustomSection")
            Console.WriteLine("Default Permission: {0}", _
            section.Permission.ToString())
        Catch e As System.Exception
            Console.WriteLine(e.Message)
        End Try
    
    End Sub
    
    
    Public Shared Sub SetPermission() 
        Try
            Dim config _
            As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)
            
            Dim section As CustomSection = _
            config.Sections.Get("CustomSection")
            
            section.Permission = _
            CustomSection.Permissions.FullControl
            
            section.SectionInformation.ForceSave = True
            config.Save(ConfigurationSaveMode.Full)
            config.Save()
            
            Console.WriteLine( _
            "Current Protection: {0}", _
            section.Permission.ToString())
        Catch e As System.Exception
            Console.WriteLine(e.Message)
        End Try
    
    End Sub
End Class

次のコード例は、前の例でアクセスするカスタム列挙子プロパティを定義する方法を示しています。 型を指定 GenericEnumConverter する必要はありません。システムによって暗黙的に呼び出されます。


public enum Permissions
{
    FullControl         = 0,
    Modify              = 1,
    ReadExecute         = 2,
    Read                = 3,
    Write               = 4,
    SpecialPermissions  = 5
}

[ConfigurationProperty("permission", DefaultValue = Permissions.Read)]
public Permissions Permission
{
    get
    {
        return (Permissions)this["permission"];
    }

    set
    {
        this["permission"] = value;
    }
}

Public Enum Permissions
    FullControl = 0
    Modify = 1
    ReadExecute = 2
    Read = 3
    Write = 4
    SpecialPermissions = 5
End Enum 'Permissions


<ConfigurationProperty("permission", _
DefaultValue:=Permissions.Read)> _
Public Property Permission() As Permissions
    Get
        Return CType(Me("permission"), Permissions)
    End Get

    Set(ByVal value As Permissions)
        Me("permission") = Value
    End Set
End Property

次の例は、前の例で使用した構成の抜粋です。

<?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" cdStr="str0, str1" permission="Read" maxUsers="Infinite"/>  

</configuration>  

注釈

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

特に、オブジェクトはGenericEnumConverter、構成プロパティに割り当てられた値を値にEnum変換Stringし、その逆も同様です。

コンストラクター

GenericEnumConverter(Type)

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

メソッド

CanConvertFrom(ITypeDescriptorContext, Type)

変換できるかどうかを確認します。

(継承元 ConfigurationConverterBase)
CanConvertFrom(Type)

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

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

変換できるかどうかを確認します。

(継承元 ConfigurationConverterBase)
CanConvertTo(Type)

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

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

StringEnum 型に変換します。

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)

Enum 型を String 値に変換します。

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)

適用対象

こちらもご覧ください