找不到继承的成员

时间:2016-12-27 18:27:03

标签: c# inheritance

我有一个名为KeyRatioSymbol的基类。 我有一个继承自KeyRatioSymbol的类,名为GuruFocusKeyRatioSymbol。

KeyRatioSymbol有这种更新方法:

        /// <summary>
    /// Updates an existing key ratio symbol by setting the values from the new <see cref="KeyRatioSymbol"/>.
    /// </summary>
    public virtual void Update<T>(T newKeyRatioSymbol) where T : KeyRatioSymbol
    {
        this.Identifier = newKeyRatioSymbol.Identifier;
    }

GuruFocusKeyRatioSymbol定义成员CurrencyId,并希望在更新时覆盖update方法以包含新的CurrencyId:

        private int _CurrencyId;
    /// <summary>
    ///  Gets or sets the CurrencyId
    /// </summary>
    public int CurrencyId { get { return this._CurrencyId; } set { this.SetProperty(ref this._CurrencyId, value); } }


    public override void Update<GuruFocusKeyRatioSymbol>(GuruFocusKeyRatioSymbol newKeyRatioSymbol)
    {
        base.Update(newKeyRatioSymbol);
        this.CurrencyId = x.CurrencyId; // Compiler error
    }

现在编译器抱怨:'GuruFocusKeyRatioSymbol'不包含'CurrencyId'的定义......

为什么编译器在类GuruFocusKeyRatioSymbol中找不到CurrencyId memeber?

问候!

1 个答案:

答案 0 :(得分:2)

T方法中,您只需命名通用参数GuruFocusKeyRatioSymbol,而在父级中使用名称GuruFocusKeyRatioSymbol。命名泛型参数T并不意味着它将属于您的CurrencyID类型,您现在只有两个具有相同名称的不同类型。如果命名泛型方法参数findstatic,这是常见的约定,它将具有相同的行为,但是很明显为什么该类型的对象不一定具有static;它们可以是任何类型的键比符号,而不仅仅是那个特定的符号。

相关问题