C# 调高编码质量
Pay pay = new Pay();
User userModel = new User();
Dictionary<int, User> myDic = new Dictionary<int, User>()
{
{2,userModel }
};
//修改新版日志格式
string result = pay.Send<Dictionary<int, User>, User>(TestMethod, myDic, userModel, Log, DoOther);
测试 Func<T, T1, T2, T3, T4, TResult> TResult表示 委托所返回值 所代表的类型, T,T1,T2,T3,T4表示委托所调用的方法的参数类型。
//Func位于System.Core命名空间下,使用委托可以提升效率,例如在反射中使用就可以弥补反射所损失的性能。
public string Send<T, T2>(Func<T,User,string> funcDo,T context,User model, Func<string,Exception,string,string> funcLog,Func<string,string> funcDoOther)
{
string result = string.Empty;
try
{
int x = 0;
model.Id = "001";
model.Name = "鲁智深";
model.Pwd = "123456";
result = funcDo(context, model);
x = x / x;
}
catch (Exception ex)
{
result = "error";
funcLog(ex.Message, ex, ex.Message);
}
finally
{
funcDoOther("总计");
}
return result;
}
- 点赞
- 收藏
- 关注作者
评论(0)