我有以下类:
在我的 AccountingItemBase 类中,我有以下属性:
我该如何将子属性的父属性设置为其本身(在父类内部)?
public class AccountingBase<TItemType> where TItemType : AccountingItemBase
在我的 AccountingItemBase 类中,我有以下属性:
public virtual AccountingBase<AccountingItemBase> Parent { get; set; }
在我的AccountingBase中,我正在尝试执行以下操作:
item.Parent = this;
从逻辑上讲,这应该是可行的,因为TItemType继承自AccountingItemBase,但实际上我收到了以下错误:
> Error 1 Cannot implicitly convert type
> 'TGS.MySQL.DataBaseObjects.AccountingBase<TItemType>'
> to
> 'TGS.MySQL.DataBaseObjects.AccountingBase<TGS.MySQL.DataBaseObjects.AccountingItemBase>'
我该如何将子属性的父属性设置为其本身(在父类内部)?
TItemType
的声明(包括命名空间)吗? - jcolebrandTItemType
是一个类型参数。它没有单独的声明。 - Jon Skeet