我正在使用RX扩展和WF4来创建一个工作流程,该工作流程对可观察的消息作出反应以推进工作流程.为此,我引入了一个包含IObservable的对象(ModuleMessage是我的抽象类.)我遇到的问题是.Subscribe无法识别任何扩展方法,即lambda extpressions /方法组.在以下代码中,我有参考:
using System.Activities;
using System.Activities.Hosting;
using System.Collections.Generic;
using System.Reactive.Linq;
Run Code Online (Sandbox Code Playgroud)
还有以下代码行:
internal void AddModuleCallback(IModule module)
{
if (!addedCallback)
{
addedCallback = true;
module.Messages.Where(m => m is MemberLeftModuleMessage || m is MemberRemovedModuleMessage).Subscribe(m => this.OnMemberExit(m)); // This line errors
}
}
internal void OnMemberExit(ModuleMessage message)
{
// Gizmo was fired, resume the bookmark
this.instance.BeginResumeBookmark(
new Bookmark(ModuleVisit.BookmarkName),
message is MemberLeftModuleMessage,
r => this.instance.EndResumeBookmark(r),
null);
}
Run Code Online (Sandbox Code Playgroud)
编译时错误:
Error 1 Cannot convert lambda expression to type 'System.IObserver<Components.Messages.ModuleMessage>' because it is not a delegate type …
Run Code Online (Sandbox Code Playgroud) 似乎没有用于指定this()和base()构造函数的语言语法.给出以下代码:
public class Bar : Foo
{
public Bar()
:base(1)
//:this(0)
{ }
public Bar(int schmalue)
:Foo(1)
{
//Gobs of initialization code
...
Schmalue = schmalue;
}
public int Schmalue { get; private set; }
}
public class Foo
{
public Foo()
{
Value = 0;
}
public class Foo(int value)
{
Value = value;
}
public int Value { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
编译器给出了一个错误,指出在取消注释:this(0)调用时预期'{'.这很麻烦,因为它导致我将我的代码分解为私有方法,当明确提供此功能以防止这样的事情.
我只是做错了吗?我试过没有分隔符,分号,逗号......这似乎只是开发团队的疏忽.我很感兴趣为什么这个被省略了,如果我以错误的方式解决这个问题,或者是否有人对替代方案提出了很好的建议.
有人看到任何缺点吗?应该注意的是,你不能从事件委托列表中删除匿名方法,我知道这一点(实际上这是概念上的动机).
这里的目标是替代:
if (onFoo != null) onFoo.Invoke(this, null);
Run Code Online (Sandbox Code Playgroud)
和代码:
public delegate void FooDelegate(object sender, EventArgs e);
public class EventTest
{
public EventTest()
{
onFoo += (p,q) => { };
}
public FireFoo()
{
onFoo.Invoke(this, null);
}
public event FooDelegate onFoo;
Run Code Online (Sandbox Code Playgroud)
}
我在一家公司工作,我们的设计团队选择使用"Field1".."Field10"作为通用的,未来的专栏.我向他们询问了原因,并告诉他们他们在那里以防我们将来需要它们.
有没有人听说过这种做法?当我看到这样的东西时,我的下巴掉到地上是不对的?
我注意到其他开发人员使用这种技术,但它总是让我困惑.我决定今天上午进行调查,并遇到下列来到MSDN(从http://msdn.microsoft.com/en-us/library/d5x73970(v=vs.100).aspx):
public class GenericList<T> where T : Employee
{
...
}
Run Code Online (Sandbox Code Playgroud)
为什么我们要使用此方法而不是在类中用Employee替换T的所有实例?对我来说,这似乎是可维护性的胜利.我可以理解限制接口作为包含来自不同继承层次结构的类的方法,但是继承已经以更明显的方式解决了上面的问题,不是吗?
这可能被视为一个错误,或者"修复"这样的代码是错误的吗?