ConfigurationConverterBase.CanConvertFrom 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
決定是否允許轉換。
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
參數
用於型別轉換的 ITypeDescriptorContext 物件。
傳回
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 是否能對強型別屬性進行轉換,以取得設定檔中使用的值字串。