需要知道如何创建DelegateCommand;返回一个整数值
这就是我正在尝试做的事情。请密切注意 InsertConlogEntry 以及我如何尝试将其分配给我的 DelegateCommand,但是,我如何处理返回 int?
谢谢你,
#region Members
public static readonly string AddConlogEntry = "AddConlogEntry";
public static readonly string GetConlogList = "GetConlogList";
public static readonly string GetConlogEntry = "GetConlogEntry";
public static readonly string Scope = "ConLog";
#endregion
#region Ctor
public ConLogCommands() :base()
{
scope = Scope;
DelegateCommand<ConlogEntryData> AddEntryCmd = new DelegateCommand<ConlogEntryData>("Add New Conlog Entry",
"AddConLogEntry", InsertConlogEntry);
this.Add(AddEntryCmd);
}
#endregion
#region Methods
private int InsertConlogEntry(ConlogEntryData data)
{
ConlogService service = new ConlogService();
return service.InsertConlogEntry(data.LoanNumber, data.UserId, data.Subject, data.Comment, data.EntryDate);
}
Here is what I am trying to do. Pay close attention to the InsertConlogEntry and how I am trying to assign it to my DelegateCommand, but, how do I handle the return int?
Thank you,
#region Members
public static readonly string AddConlogEntry = "AddConlogEntry";
public static readonly string GetConlogList = "GetConlogList";
public static readonly string GetConlogEntry = "GetConlogEntry";
public static readonly string Scope = "ConLog";
#endregion
#region Ctor
public ConLogCommands() :base()
{
scope = Scope;
DelegateCommand<ConlogEntryData> AddEntryCmd = new DelegateCommand<ConlogEntryData>("Add New Conlog Entry",
"AddConLogEntry", InsertConlogEntry);
this.Add(AddEntryCmd);
}
#endregion
#region Methods
private int InsertConlogEntry(ConlogEntryData data)
{
ConlogService service = new ConlogService();
return service.InsertConlogEntry(data.LoanNumber, data.UserId, data.Subject, data.Comment, data.EntryDate);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
命令是动作,而不是功能。因此,它们不应该返回任何值。
命令是响应某些输入而触发的操作。从技术上讲,逻辑应该是独立的。
话虽这么说,如果您只需要调用此方法并忽略结果,您可以将其包装在
Action
中,并使用该方法构建委托命令:Commands are meant to be actions - not functions. As such, they shouldn't return any values.
A command is meant to be an action that fires in response to some input. The logic should, technically, be self-contained.
That being said, if you need to just call this method and ignore the results, you can wrap it in an
Action<ConlogEntryData>
and build your delegate command with that:你不能。它只需要一个
Action
。You can't. It only takes an
Action<T>
.必须定义您自己的
DelegateCommand
版本,该版本接受Func
作为构造函数参数,而不是简单的Action< /代码>。
由于命令本身并不关心返回值,因此您可以像这样初始化它:
Not without defining your own version of
DelegateCommand<T>
that accepts aFunc<T, int>
as a constructor parameter rather than a simpleAction<T>
.Since the command itself doesn't care about the return value, you can initialize it like this: