我如何使4.0项目具有4.5参考.在单元测试中,我无法构建解决方案,它给了我这个警告.
警告2无法解析主要参考"PR.Wallet",因为它是针对".NETFramework,Version = v4.5.1"框架构建的.这是比当前目标框架".NETFramework,Version = v4.0"更高的版本.PR.Wallet.Tests
在存储库中,最佳和最合乎逻辑的方法是什么?
使用实体删除还是按ID删除?
public void Delete(Entity item);
VS.
public void Delete(int Id);
Run Code Online (Sandbox Code Playgroud)
我只是想知道什么是最佳实践,应该通过Entity删除(在删除之前先找到对象即可实现)还是通过Id删除(在方法上搜索对象然后删除)。
我有一个具有动态集的PropertyInfo.SetValue.意味着要设置的值是未知的.
我从互联网上得到了这样的方法.
private static Action<object, object> CreateSetAccess(MethodInfo method)
{
var obj = Expression.Parameter(typeof(object), "o");
var value = Expression.Parameter(typeof(object));
Expression<Action<object, object>> expr =
Expression.Lambda<Action<object, object>>(
Expression.Call(
Expression.Convert(obj, method.DeclaringType),
method,
Expression.Convert(value, method.GetParameters()[0].ParameterType)),
obj,
value);
return expr.Compile();
}
Run Code Online (Sandbox Code Playgroud)
这样做是创建一个表达式并对其进行编译,但是使用参数类型转换对象.
我像这样消费它.
var method2 = CreateSetAccess(property.GetSetMethod());
method2(response, valueToSet);
Run Code Online (Sandbox Code Playgroud)
发生的事情似乎是慢了 PropertyInfo.SetValue
这是我的基准
var xpathNavigator = XmlHelper.CreateXPathDocument(serviceResponse).CreateNavigator();
foreach (var propertyInformation in propertyInformationSource)
{
// Gets the node using the NodePath provided in the Attribute
var attr = propertyInformation.Value;
var pathValue = xpathNavigator.SelectSingleNode(attr.NodePath);
if (pathValue == null)
continue; …Run Code Online (Sandbox Code Playgroud)