TypeConverter.IsValid Metodo
Definizione
Indica se l'oggetto valore specificato è valido per questo tipo.Returns whether the given value object is valid for this type.
Overload
IsValid(ITypeDescriptorContext, Object) |
Indica se l'oggetto valore specificato è valido per questo tipo e per il contesto specificato.Returns whether the given value object is valid for this type and for the specified context. |
IsValid(Object) |
Indica se l'oggetto valore specificato è valido per questo tipo.Returns whether the given value object is valid for this type. |
IsValid(ITypeDescriptorContext, Object)
Indica se l'oggetto valore specificato è valido per questo tipo e per il contesto specificato.Returns whether the given value object is valid for this type and for the specified context.
public:
virtual bool IsValid(System::ComponentModel::ITypeDescriptorContext ^ context, System::Object ^ value);
public virtual bool IsValid (System.ComponentModel.ITypeDescriptorContext context, object value);
abstract member IsValid : System.ComponentModel.ITypeDescriptorContext * obj -> bool
override this.IsValid : System.ComponentModel.ITypeDescriptorContext * obj -> bool
Public Overridable Function IsValid (context As ITypeDescriptorContext, value As Object) As Boolean
Parametri
- context
- ITypeDescriptorContext
Oggetto ITypeDescriptorContext che fornisce un contesto di formato.An ITypeDescriptorContext that provides a format context.
Restituisce
true
se il valore specificato è valido per questo oggetto. false
in caso contrario.true
if the specified value is valid for this object; otherwise, false
.
Esempi
Per un esempio di questa funzione, vedere la TypeConverter classe.For an example of this function, see the TypeConverter class.
Commenti
Utilizzare il parametro context
per estrarre ulteriori informazioni sull'ambiente dal quale viene richiamato il convertitore.Use the context
parameter to extract additional information about the environment from which this converter is invoked. Questo parametro può essere null
, quindi controllarlo sempre.This parameter can be null
, so always check it. Anche le proprietà dell'oggetto di contesto possono restituire null
.Also, properties on the context object can return null
.
A partire da IsValid CanConvertFrom , il metodo intercetta le eccezioni dai metodi ConvertFrome. .NET Framework 4.NET Framework 4Starting in .NET Framework 4.NET Framework 4, the IsValid method catches exceptions from the CanConvertFrom and ConvertFrom methods. Se il tipo di valore di CanConvertFrom input fa false
in modo che restituisca o se ConvertFrom il valore di input causa la IsValid generazione di false
un'eccezione, il metodo restituisce.If the input value type causes CanConvertFrom to return false
, or if the input value causes ConvertFrom to raise an exception, the IsValid method returns false
.
Per abilitare il comportamento legacy, inserire le righe seguenti nel file di configurazione dell'applicazione, ad esempio Application1. exe. config.To enable the legacy behavior, insert the following lines into the configuration file of the application, for example, application1.exe.config.
<configuration>
<appSettings>
<add key="UseCompatibleTypeConverterBehavior" value="true" />
</appSettings>
</configuration>
Note per gli eredi
Eseguire l'override di questo metodo se il tipo che si desidera convertire supporta valori standard che possono essere convalidati.Override this method if the type you want to convert supports standard values that can be validated.
Il IsValid(ITypeDescriptorContext, Object) metodo viene usato per convalidare un valore all'interno del tipo anziché determinare value
se può essere convertito nel tipo specificato.The IsValid(ITypeDescriptorContext, Object) method is used to validate a value within the type rather than to determine if value
can be converted to the given type. Ad esempio, IsValid(ITypeDescriptorContext, Object) può essere utilizzato per determinare se un valore specificato è valido per un tipo di enumerazione.For example, IsValid(ITypeDescriptorContext, Object) can be used to determine if a given value is valid for an enumeration type. Per un esempio, vedere EnumConverter.For an example, see EnumConverter.
Vedi anche
IsValid(Object)
Indica se l'oggetto valore specificato è valido per questo tipo.Returns whether the given value object is valid for this type.
public:
bool IsValid(System::Object ^ value);
public bool IsValid (object value);
member this.IsValid : obj -> bool
Public Function IsValid (value As Object) As Boolean
Parametri
- value
- Object
Oggetto di cui eseguire il test di validità.The object to test for validity.
Restituisce
true
se il valore specificato è valido per questo oggetto. false
in caso contrario.true
if the specified value is valid for this object; otherwise, false
.
Commenti
A partire da IsValid CanConvertFrom , il metodo intercetta le eccezioni dai metodi ConvertFrome. .NET Framework 4.NET Framework 4Starting in .NET Framework 4.NET Framework 4, the IsValid method catches exceptions from the CanConvertFrom and ConvertFrom methods. Se il tipo di valore di CanConvertFrom input fa false
in modo che restituisca o se ConvertFrom il valore di input causa la IsValid generazione di false
un'eccezione, il metodo restituisce.If the input value type causes CanConvertFrom to return false
, or if the input value causes ConvertFrom to raise an exception, the IsValid method returns false
.
Per abilitare il comportamento legacy, inserire le righe seguenti nel file di configurazione dell'applicazione, ad esempio Application1. exe. config.To enable the legacy behavior, insert the following lines into the configuration file of the application, for example, application1.exe.config.
<configuration>
<appSettings>
<add key="UseCompatibleTypeConverterBehavior" value="true" />
</appSettings>
</configuration>
Note per gli eredi
Eseguire l'override di questo metodo se il tipo che si desidera convertire supporta valori standard che possono essere convalidati.Override this method if the type you want to convert supports standard values that can be validated.
Il IsValid(Object) metodo viene usato per convalidare un valore all'interno del tipo anziché determinare value
se può essere convertito nel tipo specificato.The IsValid(Object) method is used to validate a value within the type rather than to determine if value
can be converted to the given type. Ad esempio, IsValid(Object) può essere utilizzato per determinare se un valore specificato è valido per un tipo di enumerazione.For example, IsValid(Object) can be used to determine if a given value is valid for an enumeration type. Per un esempio, vedere EnumConverter.For an example, see EnumConverter.
È possibile scrivere un metodo WillConvertSucceed
personalizzato eseguendo il wrapping ConvertTo dei ConvertFrom metodi e nei blocchi di eccezioni.You can write your own WillConvertSucceed
method by wrapping the ConvertTo and ConvertFrom methods in exception blocks.