- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个我不明白的编译问题。我将生成代码以使其更易于理解,我希望我不会失去意义。错误是:
MyInterface1 does not contain definition for 'MyClass1'
这是正确的,因为 MyClass1
在 MyInterface2
中。如果我像这样切换接口(interface)的顺序:
public partial class MyPresenter : ParentPresenter<MyInterface2>, ParentPresenter<MyInterface1>
然后编译。这是怎么回事?
第一个文件:
namespace MyNameSpace
{
public partial class MyPresenter : ParentPresenter<MyInterface1>, ParentPresenter<MyInterface2>
{
public MyClass1 MyClass1 { get; set; }
public void MyMethod() {
View.MyClass1 = this.MyClass1; // compile error on View.MyClass1
}
}
}
第二个文件:
namespace MyNameSpace
{
public interface MyInterface1
{
System.Collections.IList MyList1 { set; }
}
public interface MyInterface2
{
MyClass1 MyClass1 { set; }
System.Collections.IList MyList2 { set; }
}
}
文件3:
public abstract class ParentPresenter<TView> : System.IDisposable
{
private TView _view;
private Microsoft.Practices.CompositeUI.WorkItem _workItem;
public TView View
{
get { return this._view; }
set
{
this._view = value;
this.OnViewSet();
}
}
}
编辑:将 setter 添加到 MyClass1
最佳答案
修改后问题很明显
你在做:
public partial class MyPresenter : ParentPresenter<MyInterface1>
所以这意味着您的类继承自:
public abstract class ParentPresenter<TView> : System.IDisposable
TView
是一个 MyInterface1
。
所以,您的 View
属性现在是 MyInterface1
类型,它没有 MyClass1
的定义,因此编译器错误在哪里你尝试访问 View.MyClass1
这个:
public partial class MyPresenter :
ParentPresenter<MyInterface1>,
ParentPresenter<MyInterface2>
C#不支持,那是多重继承。它只允许用于接口(interface),但不允许用于类(在最初的问题中你实现了两个接口(interface),这是支持的:编辑后你试图从两个类继承,这是不支持的)。
但是你可以这样做:
public interface MyInterface3 : MyInterface1, MyInterface2
{
}
然后你可以这样做:
public partial class MyPresenter : ParentPresenter<MyInterface3>
这意味着您的 View
必须实现两个接口(interface)(MyInterface1
和 MyInterface2
),并声明为实现 MyInterface3
(C# 也不支持 duck-typing),但从外观上看,它已经实现了所有必要的东西
关于c# - 接口(interface)顺序的意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35207607/
我有一张 table People (First_Name, Last_Name)。此表包含与示例中一样重复的记录(并非所有行都重复): First_Name Last_Name John
我用 Java 编写过很多程序,之前也涉足过 C++。我在各种 C++ 书籍中阅读了有关指针的内容,并完成了书籍中的各种示例。 我了解指针的基础知识,但有一件事我一直不清楚。指针在现实世界中的应用是什
线 .Mappings(m => m.FluentMappings.AddFromAssemblyOf() 它有什么作用?它会在派生自 ClassMap 的 Product 类的程序集中查找任
我有用于打印数字的自定义打印功能。我制作了一个 ASCII 版本和一个 UTF-16LE 版本。 UTF-16LE 版本对 0-9 使用全角代码/字符,对十六进制使用 A-F。在调试我的函数时,我注意
这是我的代码片段: float ab(float); 以后 if(ab(temp)
我在一个项目文件中包含以下代码: //begin of the file ((window) => { 'use strict'; class View extends GSM.Event
我一直在到处寻找关于 ? 用法的正确解释。和 *。我注意到我可以使用以下方法拒绝所有用户的访问: 如果我想允许某个组,我应该在其上方添加下一行: 但是当我看到人们使用 ? 时,我开始忘记什么意思,
我正在关注 melon js tutorial .这是在我的 HUD.js 文件的顶部。 game.HUD = game.HUD || {} 我以前在其他例子中见过这个。 namespace.some
我正在处理一个包含数千行代码的文件。我正在第 700 行实现一个算法。我经常不得不离开这些行来检查文件中的其他方法。 导航回到我实际编码的地方通常很痛苦。如果我可以在第 700 行设置一个航路点并为其
我遇到了这段代码 do { if (higherQuality && w > targetWidth) { w /= 2; if (w &
uint8_t * const LCDMem = (uint8_t *) &LCDM3; 此代码在 msp430fg4618 培训套件中用于 lcd 配置。谁能解释一下上述代码的含义? 它允许使用 a
上下文 阅读一些内核代码。 问题 我不明白这行是什么意思 *(void **) &(int[2]){0,PAGE_SIZE}; 还有更多,这是什么意思 {0,PAGE_SIZE} 对我来说,它看起来不
我正在查看 Underscore.js 的源代码库,专门用于 map方法(该页面第 85 行左右,并复制到此处): _.map = function(obj, iterator, context)
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我是一名优秀的程序员,十分优秀!