0
私はポイントのようなものを得るために使用する必要がある、異なる機能を持つ次のクラス/タイプを持っています。カスタムコンバータでCS1503を解決する方法
[TypeConverter(typeof(KnotenConverter))]
class Knoten
{
int x, y;
List<Knoten> neighbors;
#region gettersetter
//Standard getter and setter here
#endregion
public bool hasNeighbors()
{
return Neighbors.Count > 0;
}
class KnotenConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(Point)) return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
Knoten from = (Knoten)value;
if (destinationType == typeof(Point))
{
return new Point(from.X, from.Y);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
Knotenをポイントとして使用するために、自分自身のTypeConverterを実装してKnotenをPointに変換しました。しかし、私は得続ける
CS1503引数 '2'はGridCalcer.KnotenからSystem.Drawing.Pointに変換できません。
何が私は間違っていましたか、どうやってこのエラーを解決して、Knotenをポイントに変換することができますか?
たラインで:それを行うことができるようにするために、あなたはimplicit変換演算子を宣言する必要がありますか?それはコンバータのラインですか?どの線?または、たとえば値を設定するときに発生します。 'PropertyGrid'? – Sinatr