我面临以下问题:引用类型通过引用传递给另一种方法不返回与更新值
我需要从我的控制器进入我的域层;它调用通过引用(ref)引入请求的Web服务方法。
控制器代码:
//BusinessEntityObject is a Reference-Type (BusinessEntity) object
var request = View.BusinessEntityObject;
_workflowService.PerformAction(request);
if(request.Errors.Count != 0)
{
View.Errors = request.Errors;
return false;
}
领域层(WorkflowService.cs类):
public void PerformAction(BusinessEntity request)
{
//TryAction(System.Action action) basically wraps action in try catch and handles exceptions
TryAction(() =>
{
_wcfClient.RequestSomething(ref request);
});
}
IF _wcfClient.RequestSomething
一旦返回修改Errors集合的请求对象具有更新这个错误的错误采集。但是,一旦控制返回到控制器&错误收集被检查,然后我的更新消失。
Edit00:ohh和无耻的插头,我在代表14,我试图碰到一堆对我有用的问题/答案,它说我不能因为我的水平低。
Edit01:非常感谢Dylan,看到总有这样的网站指出可能会错过的非常小的事情。返回的值给我更新的代码如下:
领域层(WorkflowService.cs类):
public BusinessEntity PerformAction(BusinessEntity request)
{
//TryAction(System.Action action) basically wraps action in try catch and handles exceptions
TryAction(() =>
{
_wcfClient.RequestSomething(ref request);
return request;
});
}
按设计,您不希望域层修改BusinessEntityObject中的某些内容。您可以根据需要修改异常 – mozillanerd