語言

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 是否能對強型別屬性進行轉換,以取得設定檔中使用的值字串。

適用於