通用 - 最佳重载方法匹配具有一些无效参数

时间:2014-10-08 10:13:08

标签: c# generics

我有一个这样的抽象类:

public abstract class Placement<T>
        where T : IElement
{ }

我还有另一个继承它的类:

public class ResourcePlacement : Placement<Resource>
{ }

某处我有业务逻辑,可以将位置保存到数据库中:

public interface IPlacementManagement<T, TPlacement>
        where T : IElement
        where TPlacement : Placement<T>
{     
        void SavePlacement(TPlacement placement);
}

abstract class PlacementManagementImplBase<T, TPlacement> : IPlacementManagement<T, TPlacement>
        where T : IElement
        where TPlacement : Placement<T>
{
    public virtual void SavePlacement(TPlacement placement)
    {
        // Implementation.
    }
}

在客户端,我试图像这样保存它:

var placement = new ResourcePlacement();
// Do something with placement.
this.placementMangagement.SavePlacement(placement);

但是我收到以下错误:

the best overloaded method match for IPlacementManagement<TEntity, TPlacement>.SavePlacement(TPlacement) has some invalid arguments.

为什么会出现此错误? 如何在ResourcePlacement方法中将SavePlacement实例作为参数传递?

0 个答案:

没有答案