ConfigurationConverterBase.CanConvertTo(ITypeDescriptorContext, Type) 方法

定義

判斷是否允許轉換。

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

參數

ctx
ITypeDescriptorContext

用於型別轉換的 ITypeDescriptorContext 物件。

type
Type

要轉換的目標類型。

傳回

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

範例

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

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

End Function 'CanConvertTo

備註

方法 CanConvertTo 會判斷組態檔中包含的字串是否可以轉換成相關的強型別屬性。

適用於