ConfigurationConverterBase.CanConvertFrom 方法

定義

判斷是否允許轉換。

public:
 override bool CanConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ ctx, Type ^ type);
public override bool CanConvertFrom (System.ComponentModel.ITypeDescriptorContext ctx, Type type);
override this.CanConvertFrom : System.ComponentModel.ITypeDescriptorContext * Type -> bool
Public Overrides Function CanConvertFrom (ctx As ITypeDescriptorContext, type As Type) As Boolean

參數

ctx
ITypeDescriptorContext

ITypeDescriptorContext 物件用於型別轉換。

type
Type

要進行轉換的來源 Type

傳回

如果允許轉換,則為 true,否則為 false

範例

下列範例程式代碼示範如何覆寫 CanConvertFrom 方法來建立自定義 TimeSpan 轉換器類型。 此外,此範例也會示範如何在自定義區段中使用此類型。

public override bool CanConvertFrom(
    ITypeDescriptorContext ctx, Type type)
{
    return (type == typeof(string));
}
Public Overrides Function CanConvertFrom( _
ByVal ctx As ITypeDescriptorContext, _
ByVal type As Type) As Boolean
    Return (type.ToString() = GetType(String).ToString())

End Function 'CanConvertFrom

備註

方法 CanConvertFrom 會決定是否可以在強型別屬性上執行轉換,以取得組態檔中使用的值字串。

適用於