ExpandableObjectConverter Classe
Definição
Fornece um conversor de tipo para converter objetos expansíveis de e para diversas outras representações.Provides a type converter to convert expandable objects to and from various other representations.
public ref class ExpandableObjectConverter : System::ComponentModel::TypeConverter
public class ExpandableObjectConverter : System.ComponentModel.TypeConverter
type ExpandableObjectConverter = class
inherit TypeConverter
Public Class ExpandableObjectConverter
Inherits TypeConverter
- Herança
- Derivado
Exemplos
O exemplo de código a seguir converte uma variável do tipo Margins em uma variável de cadeia de caracteres.The following code example converts a variable of type Margins to a string variable.
String^ strM = "1,2,3,4";
System::Drawing::Printing::Margins^ m = gcnew System::Drawing::Printing::Margins( 1,2,3,4 );
Console::WriteLine( TypeDescriptor::GetConverter( strM )->CanConvertTo( System::Drawing::Printing::Margins::typeid ) );
Console::WriteLine( TypeDescriptor::GetConverter( m )->ConvertToString( m ) );
string strM="1,2,3,4";
System.Drawing.Printing.Margins m= new System.Drawing.Printing.Margins(1,2,3,4);
Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(typeof(System.Drawing.Printing.Margins)));
Console.WriteLine(TypeDescriptor.GetConverter(m).ConvertToString(m));
Dim strM As String
strM = "1,2,3,4"
Dim m As New System.Drawing.Printing.Margins(1, 2, 3, 4)
Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(GetType(System.Drawing.Printing.Margins)))
Console.WriteLine(TypeDescriptor.GetConverter(m).ConvertToString(m))
O exemplo de código a seguir demonstra como usar o NotifyParentPropertyAttribute e a ExpandableObjectConverter classe para criar uma propriedade expansível em um controle personalizado.The following code example demonstrates how to use the NotifyParentPropertyAttribute and the ExpandableObjectConverter class to create an expandable property on a custom control. Este exemplo de código faz parte de um exemplo maior fornecido para a NotifyParentPropertyAttribute classe.This code example is part of a larger example provided for the NotifyParentPropertyAttribute class.
[TypeConverter(typeof(BorderAppearanceConverter))]
public class BorderAppearance
{
private int borderSizeValue = 1;
private Color borderColorValue = Color.Empty;
[Browsable(true),
NotifyParentProperty(true),
EditorBrowsable(EditorBrowsableState.Always),
DefaultValue(1)]
public int BorderSize
{
get
{
return borderSizeValue;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(
"BorderSize",
value,
"must be >= 0");
}
if (borderSizeValue != value)
{
borderSizeValue = value;
}
}
}
[Browsable(true)]
[NotifyParentProperty(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DefaultValue(typeof(Color), "")]
public Color BorderColor
{
get
{
return borderColorValue;
}
set
{
if (value.Equals(Color.Transparent))
{
throw new NotSupportedException("Transparent colors are not supported.");
}
if (borderColorValue != value)
{
borderColorValue = value;
}
}
}
}
<TypeConverter(GetType(BorderAppearanceConverter))> _
Public Class BorderAppearance
Private borderSizeValue As Integer = 1
Private borderColorValue As Color = Color.Empty
<Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(1)> _
Public Property BorderSize() As Integer
Get
Return borderSizeValue
End Get
Set
If value < 0 Then
Throw New ArgumentOutOfRangeException("BorderSize", value, "must be >= 0")
End If
If borderSizeValue <> value Then
borderSizeValue = value
End If
End Set
End Property
<Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")> _
Public Property BorderColor() As Color
Get
Return borderColorValue
End Get
Set
If value.Equals(Color.Transparent) Then
Throw New NotSupportedException("Transparent colors are not supported.")
End If
If borderColorValue <> value Then
borderColorValue = value
End If
End Set
End Property
End Class
Comentários
Essa classe adiciona suporte a propriedades em um objeto para os métodos e propriedades fornecidos pelo TypeConverter .This class adds support for properties on an object to the methods and properties provided by TypeConverter. Para tornar um tipo de propriedade expansível no PropertyGrid , especifique-o TypeConverter para implementações padrão do GetPropertiesSupported e do GetProperties .To make a type of property expandable in the PropertyGrid, specify this TypeConverter for standard implementations of GetPropertiesSupported and GetProperties. Marque Propriedades filhas com o NotifyParentPropertyAttribute para garantir o comportamento correto em um PropertyGrid controle.Mark child properties with the NotifyParentPropertyAttribute to ensure correct behavior in a PropertyGrid control.
Observação
Você nunca deve acessar um conversor de tipo diretamente.You should never access a type converter directly. Em vez disso, chame o conversor apropriado usando TypeDescriptor .Instead, call the appropriate converter by using TypeDescriptor. Para obter mais informações, consulte os exemplos na TypeConverter classe base.For more information, see the examples in the TypeConverter base class.
Para obter mais informações sobre conversores de tipo, consulte a TypeConverter classe base e como: implementar um conversor de tipo.For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.
Construtores
| ExpandableObjectConverter() |
Inicializa uma nova instância da classe ExpandableObjectConverter.Initializes a new instance of the ExpandableObjectConverter class. |
Métodos
| CanConvertFrom(ITypeDescriptorContext, Type) |
Retorna se esse conversor pode converter um objeto do tipo especificado no tipo desse conversor, usando o contexto especificado.Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context. (Herdado de TypeConverter) |
| CanConvertFrom(Type) |
Retorna se este conversor pode converter um objeto do tipo indicado para o tipo deste conversor.Returns whether this converter can convert an object of the given type to the type of this converter. (Herdado de TypeConverter) |
| CanConvertTo(ITypeDescriptorContext, Type) |
Retorna se esse conversor pode converter o objeto para o tipo especificado, usando o contexto especificado.Returns whether this converter can convert the object to the specified type, using the specified context. (Herdado de TypeConverter) |
| CanConvertTo(Type) |
Retorna se esse conversor pode converter o objeto para o tipo especificado.Returns whether this converter can convert the object to the specified type. (Herdado de TypeConverter) |
| ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) |
Converte o objeto determinado para o tipo deste conversor, usando o contexto especificado e as informações da cultura.Converts the given object to the type of this converter, using the specified context and culture information. (Herdado de TypeConverter) |
| ConvertFrom(Object) |
Converte o valor fornecido noo tipo deste conversor.Converts the given value to the type of this converter. (Herdado de TypeConverter) |
| ConvertFromInvariantString(ITypeDescriptorContext, String) |
Converte a cadeia de caracteres fornecida para o tipo deste conversor usando a cultura invariável e o contexto especificado.Converts the given string to the type of this converter, using the invariant culture and the specified context. (Herdado de TypeConverter) |
| ConvertFromInvariantString(String) |
Converte a cadeia de caracteres fornecida para o tipo deste conversor usando a cultura invariável.Converts the given string to the type of this converter, using the invariant culture. (Herdado de TypeConverter) |
| ConvertFromString(ITypeDescriptorContext, CultureInfo, String) |
Converte o texto fornecido em um objeto, usando o contexto e a informação de cultura especificados.Converts the given text to an object, using the specified context and culture information. (Herdado de TypeConverter) |
| ConvertFromString(ITypeDescriptorContext, String) |
Converte o texto fornecido em um objeto, usando o contexto especificado.Converts the given text to an object, using the specified context. (Herdado de TypeConverter) |
| ConvertFromString(String) |
Converte o texto especificado em um objeto.Converts the specified text to an object. (Herdado de TypeConverter) |
| ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type) |
Converte o objeto de valor determinado para o tipo especificado, usando o contexto especificado e as informações da cultura.Converts the given value object to the specified type, using the specified context and culture information. (Herdado de TypeConverter) |
| ConvertTo(Object, Type) |
Converte o objeto de valor especificado para o tipo especificado, usando os argumentos.Converts the given value object to the specified type, using the arguments. (Herdado de TypeConverter) |
| ConvertToInvariantString(ITypeDescriptorContext, Object) |
Converte o valor especificado em uma representação de cadeia de caracteres que não varia de acordo com a cultura, usando o contexto especificado.Converts the specified value to a culture-invariant string representation, using the specified context. (Herdado de TypeConverter) |
| ConvertToInvariantString(Object) |
Converte o valor especificado em uma representação de cadeia de caracteres invariável da cultura.Converts the specified value to a culture-invariant string representation. (Herdado de TypeConverter) |
| ConvertToString(ITypeDescriptorContext, CultureInfo, Object) |
Converte o valor especificado em uma representação de cadeia de caracteres, usando as informações de contexto e cultura especificadas.Converts the given value to a string representation, using the specified context and culture information. (Herdado de TypeConverter) |
| ConvertToString(ITypeDescriptorContext, Object) |
Converte o valor especificado em uma representação de cadeia de caracteres, usando o contexto fornecido.Converts the given value to a string representation, using the given context. (Herdado de TypeConverter) |
| ConvertToString(Object) |
Converte o valor especificado em uma representação de cadeia de caracteres.Converts the specified value to a string representation. (Herdado de TypeConverter) |
| CreateInstance(IDictionary) |
Recria um Object dado um conjunto de valores de propriedade do objeto.Re-creates an Object given a set of property values for the object. (Herdado de TypeConverter) |
| CreateInstance(ITypeDescriptorContext, IDictionary) |
Cria uma instância do tipo ao qual esse TypeConverter está associado, usando o contexto especificado, dado um conjunto de valores de propriedade para o objeto.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. (Herdado de TypeConverter) |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetConvertFromException(Object) |
Retorna uma exceção a ser gerada quando uma conversão não puder ser executada.Returns an exception to throw when a conversion cannot be performed. (Herdado de TypeConverter) |
| GetConvertToException(Object, Type) |
Retorna uma exceção a ser gerada quando uma conversão não puder ser executada.Returns an exception to throw when a conversion cannot be performed. (Herdado de TypeConverter) |
| GetCreateInstanceSupported() |
Retorna se a alteração de um valor neste objeto requer uma chamada ao método CreateInstance(IDictionary) para criar um novo valor.Returns whether changing a value on this object requires a call to the CreateInstance(IDictionary) method to create a new value. (Herdado de TypeConverter) |
| GetCreateInstanceSupported(ITypeDescriptorContext) |
Retorna se a alteração de um valor neste objeto requer uma chamada para CreateInstance(IDictionary) para criar um novo valor, usando o contexto especificado.Returns whether changing a value on this object requires a call to CreateInstance(IDictionary) to create a new value, using the specified context. (Herdado de TypeConverter) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetProperties(ITypeDescriptorContext, Object) |
Retorna uma coleção de propriedades para o tipo de matriz especificado pelo parâmetro de valor, usando o contexto especificado.Returns a collection of properties for the type of array specified by the value parameter, using the specified context. (Herdado de TypeConverter) |
| GetProperties(ITypeDescriptorContext, Object, Attribute[]) |
Obtém uma coleção de propriedades para o tipo de objeto especificado pelo parâmetro de valor.Gets a collection of properties for the type of object specified by the value parameter. |
| GetProperties(Object) |
Retorna uma coleção de propriedades para o tipo de matriz especificado pelo parâmetro de valor.Returns a collection of properties for the type of array specified by the value parameter. (Herdado de TypeConverter) |
| GetPropertiesSupported() |
Retorna se este objeto dá suporte a propriedades.Returns whether this object supports properties. (Herdado de TypeConverter) |
| GetPropertiesSupported(ITypeDescriptorContext) |
Obtém um valor que indica se este objeto dá suporte às propriedades usando o contexto especificado.Gets a value indicating whether this object supports properties using the specified context. |
| GetStandardValues() |
Retorna uma coleção de valores padrão do contexto padrão para o tipo de dados para o qual esse conversor de tipo foi criado.Returns a collection of standard values from the default context for the data type this type converter is designed for. (Herdado de TypeConverter) |
| GetStandardValues(ITypeDescriptorContext) |
Retorna uma coleção de valores padrão para o tipo de dados para o qual esse conversor de tipo foi criado quando fornecido com um contexto de formato.Returns a collection of standard values for the data type this type converter is designed for when provided with a format context. (Herdado de TypeConverter) |
| GetStandardValuesExclusive() |
Retorna se a coleção de valores padrão retornada de GetStandardValues() é uma lista exclusiva.Returns whether the collection of standard values returned from GetStandardValues() is an exclusive list. (Herdado de TypeConverter) |
| GetStandardValuesExclusive(ITypeDescriptorContext) |
Retorna se a coleção de valores padrão retornada de GetStandardValues() é uma lista exclusiva de possíveis valores, usando o contexto especificado.Returns whether the collection of standard values returned from GetStandardValues() is an exclusive list of possible values, using the specified context. (Herdado de TypeConverter) |
| GetStandardValuesSupported() |
Retorna se este objeto dá suporte a um conjunto padrão de valores que podem ser escolhidos em uma lista.Returns whether this object supports a standard set of values that can be picked from a list. (Herdado de TypeConverter) |
| GetStandardValuesSupported(ITypeDescriptorContext) |
Retorna se o objeto dá suporte a um conjunto de valores padrão que podem ser escolhidos de uma lista, usando o contexto especificado.Returns whether this object supports a standard set of values that can be picked from a list, using the specified context. (Herdado de TypeConverter) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| IsValid(ITypeDescriptorContext, Object) |
Retorna se o objeto de valor fornecido é válido para esse tipo e para o contexto especificado.Returns whether the given value object is valid for this type and for the specified context. (Herdado de TypeConverter) |
| IsValid(Object) |
Retorna se o objeto de valor especificado é válido para esse tipo.Returns whether the given value object is valid for this type. (Herdado de TypeConverter) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| SortProperties(PropertyDescriptorCollection, String[]) |
Classifica uma coleção de propriedades.Sorts a collection of properties. (Herdado de TypeConverter) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |