EnumConverter Třída
Definice
public ref class EnumConverter : System::ComponentModel::TypeConverter
public class EnumConverter : System.ComponentModel.TypeConverter
type EnumConverter = class
inherit TypeConverter
Public Class EnumConverter
Inherits TypeConverter
- Dědičnost
- Odvozené
Příklady
Následující příklad kódu převede proměnnou typu Enum na řetězec a naopak.The following code example converts a variable of type Enum to a string, and vice versa. Příklad vyžaduje, abyste deklarovali, že jste Enum volali Servers a že má následující členy:The example requires that you have declared an Enum called Servers and that it has the following members:
Windows=1, Exchange=2, BizTalk=3
// Requires public declaration of the following type.
// __value enum Servers {Windows=1, Exchange=2, BizTalk=3};
Servers myServer = Servers::Exchange;
String^ myServerString = "BizTalk";
Console::WriteLine( TypeDescriptor::GetConverter( myServer )->ConvertTo( myServer, String::typeid ) );
Console::WriteLine( TypeDescriptor::GetConverter( myServer )->ConvertFrom( myServerString ) );
Enum myServer= Servers.Exchange;
string myServerString = "BizTalk";
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertTo(myServer, typeof(string)));
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertFrom(myServerString));
Dim myServer As Servers = Servers.Exchange
Dim myServerString As string = "BizTalk"
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertTo(myServer, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertFrom(myServerString))
Poznámky
Tento převaděč může převést pouze objekt výčtu na řetězec a z něj.This converter can only convert an enumeration object to and from a string. EnumConverterTřída poskytuje Comparer vlastnost pro získání IComparer rozhraní, které lze použít k řazení hodnot výčtu.The EnumConverter class provides the Comparer property to get an IComparer interface that can be used to sort the values of the enumeration. Ve výchozím nastavení jsou hodnoty výčtu řazeny v pořadí, v jakém jsou uvedeny v souboru.By default, the enumeration values are sorted in the order they appear in the file.
Další informace o převaděčích typů naleznete v TypeConverter základní třídě a Postupy: Implementace konvertoru typu.For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.
Poznámka
Nikdy byste neměli vytvořit instanci typu EnumConverter .You should never create an instance of an EnumConverter. Místo toho zavolejte GetConverter metodu TypeDescriptor třídy.Instead, call the GetConverter method of the TypeDescriptor class. Další informace naleznete v příkladech v TypeConverter základní třídě.For more information, see the examples in the TypeConverter base class.
Poznámky pro dědice
Pokud chcete hodnoty seřadit do jiného pořadí, přepište Comparer vlastnost.If you want to sort the values into a different order, override the Comparer property.
Konstruktory
| EnumConverter(Type) |
Inicializuje novou instanci EnumConverter třídy pro daný typ.Initializes a new instance of the EnumConverter class for the given type. |
Vlastnosti
| Comparer |
Získá objekt IComparer , který lze použít k řazení hodnot výčtu.Gets an IComparer that can be used to sort the values of the enumeration. |
| EnumType |
Určuje typ čítače, ke kterému je tento převodník přidružen.Specifies the type of the enumerator this converter is associated with. |
| Values |
Získá nebo nastaví hodnotu TypeConverter.StandardValuesCollection , která určuje možné hodnoty pro výčet.Gets or sets a TypeConverter.StandardValuesCollection that specifies the possible values for the enumeration. |
Metody
| CanConvertFrom(ITypeDescriptorContext, Type) |
Získá hodnotu, která označuje, zda tento převaděč může převést objekt v zadaném zdrojovém typu na objekt výčtu pomocí zadaného kontextu.Gets a value indicating whether this converter can convert an object in the given source type to an enumeration object using the specified context. |
| CanConvertFrom(Type) |
Vrátí, zda tento převaděč může převést objekt daného typu na typ tohoto převaděče.Returns whether this converter can convert an object of the given type to the type of this converter. (Zděděno od TypeConverter) |
| CanConvertTo(ITypeDescriptorContext, Type) |
Získá hodnotu, která označuje, zda tento převaděč může převést objekt na daný cílový typ pomocí kontextu.Gets a value indicating whether this converter can convert an object to the given destination type using the context. |
| CanConvertTo(Type) |
Vrátí, zda tento převaděč může převést objekt na zadaný typ.Returns whether this converter can convert the object to the specified type. (Zděděno od TypeConverter) |
| ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) |
Převede zadaný objekt hodnoty na objekt výčtu.Converts the specified value object to an enumeration object. |
| ConvertFrom(Object) |
Převede danou hodnotu na typ tohoto převaděče.Converts the given value to the type of this converter. (Zděděno od TypeConverter) |
| ConvertFromInvariantString(ITypeDescriptorContext, String) |
Převede daný řetězec na typ tohoto převaděče s použitím neutrální jazykové verze a zadaného kontextu.Converts the given string to the type of this converter, using the invariant culture and the specified context. (Zděděno od TypeConverter) |
| ConvertFromInvariantString(String) |
Převede daný řetězec na typ tohoto převaděče s použitím invariantní jazykové verze.Converts the given string to the type of this converter, using the invariant culture. (Zděděno od TypeConverter) |
| ConvertFromString(ITypeDescriptorContext, CultureInfo, String) |
Převede daný text na objekt pomocí zadaných informací o kontextu a jazykové verzi.Converts the given text to an object, using the specified context and culture information. (Zděděno od TypeConverter) |
| ConvertFromString(ITypeDescriptorContext, String) |
Převede daný text na objekt pomocí zadaného kontextu.Converts the given text to an object, using the specified context. (Zděděno od TypeConverter) |
| ConvertFromString(String) |
Převede zadaný text na objekt.Converts the specified text to an object. (Zděděno od TypeConverter) |
| ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type) |
Převede daný objekt hodnoty na zadaný cílový typ.Converts the given value object to the specified destination type. |
| ConvertTo(Object, Type) |
Převede daný objekt Value na zadaný typ pomocí argumentů.Converts the given value object to the specified type, using the arguments. (Zděděno od TypeConverter) |
| ConvertToInvariantString(ITypeDescriptorContext, Object) |
Převede zadanou hodnotu na reprezentaci typu invariantní řetězcové verze pomocí zadaného kontextu.Converts the specified value to a culture-invariant string representation, using the specified context. (Zděděno od TypeConverter) |
| ConvertToInvariantString(Object) |
Převede zadanou hodnotu na reprezentaci neutrální řetězcové verze.Converts the specified value to a culture-invariant string representation. (Zděděno od TypeConverter) |
| ConvertToString(ITypeDescriptorContext, CultureInfo, Object) |
Převede danou hodnotu na řetězcovou reprezentaci pomocí zadaných informací o kontextu a jazykové verzi.Converts the given value to a string representation, using the specified context and culture information. (Zděděno od TypeConverter) |
| ConvertToString(ITypeDescriptorContext, Object) |
Převede danou hodnotu na řetězcovou reprezentaci pomocí daného kontextu.Converts the given value to a string representation, using the given context. (Zděděno od TypeConverter) |
| ConvertToString(Object) |
Převede zadanou hodnotu na řetězcovou reprezentaci.Converts the specified value to a string representation. (Zděděno od TypeConverter) |
| CreateInstance(IDictionary) |
Znovu vytvoří Object danou sadu hodnot vlastností pro objekt.Re-creates an Object given a set of property values for the object. (Zděděno od TypeConverter) |
| CreateInstance(ITypeDescriptorContext, IDictionary) |
Vytvoří instanci typu, TypeConverter ke kterému je přidruženo, pomocí zadaného kontextu s ohledem na sadu hodnot vlastností pro objekt.Creates an instance of the type that this TypeConverter is associated with, using the specified context, given a set of property values for the object. (Zděděno od TypeConverter) |
| Equals(Object) |
Určí, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object. (Zděděno od Object) |
| GetConvertFromException(Object) |
Vrátí výjimku, která se má vyvolat, když se nedá provést převod.Returns an exception to throw when a conversion cannot be performed. (Zděděno od TypeConverter) |
| GetConvertToException(Object, Type) |
Vrátí výjimku, která se má vyvolat, když se nedá provést převod.Returns an exception to throw when a conversion cannot be performed. (Zděděno od TypeConverter) |
| GetCreateInstanceSupported() |
Vrátí, zda změna hodnoty na tomto objektu vyžaduje volání CreateInstance(IDictionary) metody pro vytvoření nové hodnoty.Returns whether changing a value on this object requires a call to the CreateInstance(IDictionary) method to create a new value. (Zděděno od TypeConverter) |
| GetCreateInstanceSupported(ITypeDescriptorContext) |
Vrátí, zda změna hodnoty na tomto objektu vyžaduje volání CreateInstance(IDictionary) k vytvoření nové hodnoty pomocí zadaného kontextu.Returns whether changing a value on this object requires a call to CreateInstance(IDictionary) to create a new value, using the specified context. (Zděděno od TypeConverter) |
| GetHashCode() |
Slouží jako výchozí funkce hash.Serves as the default hash function. (Zděděno od Object) |
| GetProperties(ITypeDescriptorContext, Object) |
Vrátí kolekci vlastností pro typ pole určeného parametrem value pomocí zadaného kontextu.Returns a collection of properties for the type of array specified by the value parameter, using the specified context. (Zděděno od TypeConverter) |
| GetProperties(ITypeDescriptorContext, Object, Attribute[]) |
Vrátí kolekci vlastností pro typ pole určeného parametrem value pomocí zadaného kontextu a atributů.Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes. (Zděděno od TypeConverter) |
| GetProperties(Object) |
Vrátí kolekci vlastností pro typ pole určeného parametrem value.Returns a collection of properties for the type of array specified by the value parameter. (Zděděno od TypeConverter) |
| GetPropertiesSupported() |
Vrátí, zda tento objekt podporuje vlastnosti.Returns whether this object supports properties. (Zděděno od TypeConverter) |
| GetPropertiesSupported(ITypeDescriptorContext) |
Vrátí, zda tento objekt podporuje vlastnosti pomocí zadaného kontextu.Returns whether this object supports properties, using the specified context. (Zděděno od TypeConverter) |
| GetStandardValues() |
Vrátí kolekci standardních hodnot z výchozího kontextu pro datový typ, pro který je tento konvertor typu určen.Returns a collection of standard values from the default context for the data type this type converter is designed for. (Zděděno od TypeConverter) |
| GetStandardValues(ITypeDescriptorContext) |
Získá kolekci standardních hodnot pro datový typ, pro který je tento validátor navržen.Gets a collection of standard values for the data type this validator is designed for. |
| GetStandardValuesExclusive() |
Vrátí, zda kolekce standardních hodnot vrácená z GetStandardValues() je exkluzivní seznam.Returns whether the collection of standard values returned from GetStandardValues() is an exclusive list. (Zděděno od TypeConverter) |
| GetStandardValuesExclusive(ITypeDescriptorContext) |
Načte hodnotu, která označuje, zda seznam standardních hodnot vrácených z GetStandardValues() je exkluzivní seznam pomocí zadaného kontextu.Gets a value indicating whether the list of standard values returned from GetStandardValues() is an exclusive list using the specified context. |
| GetStandardValuesSupported() |
Vrátí, zda tento objekt podporuje standardní sadu hodnot, které lze vybrat ze seznamu.Returns whether this object supports a standard set of values that can be picked from a list. (Zděděno od TypeConverter) |
| GetStandardValuesSupported(ITypeDescriptorContext) |
Získá hodnotu, která označuje, zda tento objekt podporuje standardní sadu hodnot, které mohou být vydány ze seznamu pomocí zadaného kontextu.Gets a value indicating whether this object supports a standard set of values that can be picked from a list using the specified context. |
| GetType() |
Získá Type aktuální instanci.Gets the Type of the current instance. (Zděděno od Object) |
| IsValid(ITypeDescriptorContext, Object) |
Načte hodnotu, která označuje, jestli je daná hodnota objektu pro tento typ platná.Gets a value indicating whether the given object value is valid for this type. |
| IsValid(Object) |
Vrátí, zda je daný objekt Value pro tento typ platný.Returns whether the given value object is valid for this type. (Zděděno od TypeConverter) |
| MemberwiseClone() |
Vytvoří kopii aktuálního seznamu Object .Creates a shallow copy of the current Object. (Zděděno od Object) |
| SortProperties(PropertyDescriptorCollection, String[]) |
Seřadí kolekci vlastností.Sorts a collection of properties. (Zděděno od TypeConverter) |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt.Returns a string that represents the current object. (Zděděno od Object) |