我有一个列表,其中包含作为泛型类型的“参考”类。所以我应该能够用“Reference”类的子类填充我的列表,但是编译器会报告一个错误:
'naturalCalc.Enginee.Reference'
不包含 for 的定义,也找不到接受第一个类型参数的'Opener'
扩展方法(您是否缺少 using 指令或程序集引用?)(CS1061)'Opener'
'naturalCalc.Enginee.Reference'
ToPostfix.cs:27,34
'ToPostfix' 类中的切换代码确保项目在第二种情况下具有 'Opener' 属性。
// The 'MyBrackets' class which contains the 'Opener' property.
public class MyBrackets : naturalCalc.Enginee.Reference
{
private bool opener;
public MyBrackets( bool opener )
{
this.opener = opener;
}
public bool Opener { get { return this.Opener; } }
}
// The 'ToPostfix' class in which the error is taken place.
class ToPostfix
{
List<Reference> infix = new List<Reference>();
List<Reference> postfix = new List<Reference>();
public ToPostfix(List<Reference> infixForm)
{
this.infix = infixForm;
foreach (Reference item in this.infix)
{
switch ( item.ToString() )
{
case "naturalCalc.Enginee.MyFloat":
this.postfix.Add(item);
break;
case "naturalCalc.Enginee.MyBrackets":
if (item.Opener)
{
this.postfix.Add(item);
}
break;
}
}
}
}