我刚刚注意到我在ASP.NET应用程序中重复了很多C#代码,所以想要创建一个通用方法.我有一系列这样的私有方法:
private void PopulateMyRepeatedControl()
{
DBUtil DB = new DBUtil();
DataTable symbols = GetSelectedSymbols();
DataTable tradeGrades = GetSelectedTradeGrades();
DataTable executionGrades = GetSelectedExecutionGrades();
chtMyRepeatedChart.DataSource = DB.MyRepeatedCall (
int.Parse(txtStartBalance.Text),
int.Parse(ddlTradeTypes.SelectedValue),
ddlRepeatedTrades.SelectedValue,
radSide.SelectedValue,
ddlTradeSetups.SelectedValue,
symbols,
ddlChartTimeFrames.SelectedValue,
int.Parse(ddlHours.SelectedValue),
int.Parse(ddlYears.SelectedValue),
int.Parse(ddlMonths.SelectedValue),
int.Parse(ddlDays.SelectedValue),
int.Parse(ddlNumSCs.SelectedValue),
txtDateFrom.Text,
txtDateTo.Text,
tradeGrades,
executionGrades,
int.Parse(txtMinProfitPips.Text),
int.Parse(txtMaxProfitPips.Text));
chtMyRepeatedChart.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
所以,我想替换DB.MyRepeatedCall,chtMyRepeatedChart并将它们作为参数传递给泛型函数.那可能吗?我的表单上有很多图表,它们使用相同数量的参数.
谢谢
更新 根据Frederik的解决方案,我做到了这一点:
private delegate IEnumerable<DataTable> GetDataSource(
int TradeType,
string RepeatedTrades,
string Side,
string TradeSetup,
DataTable symbols,
string ChartTimeFrame,
int Hour,
int Year,
int Month,
int Day,
int NumSCs, …Run Code Online (Sandbox Code Playgroud) 我有一个recuring方法,它在我的代码中多次显示它基本上检查以确保与odbc的连接是正确的然后连接但每次调用此方法时它调用另一个方法和main方法的每个实例这一个是不同的,因为每个方法大约有8行代码,在代码中有8次是不理想的.
所以基本上我想有一个方法,我可以调用传递新方法的名称作为争论.
所以基本上像:
private void doSomething(methodToBeCalled)
{
if(somthingistrue)
{
methodToBeCalled(someArgument)
}
}
这可能吗?
提前致谢
我们在一些项目中使用 FlurlClient 并熟悉它们的流畅界面。我们现在想在使用 TestServer 的 asp.net 核心集成测试中使用它。来自http://asp.net-hacker.rocks/2017/09/27/testing-aspnetcore.html的示例
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
Run Code Online (Sandbox Code Playgroud)
我打算将代码更改为
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
var httpClient = _server.CreateClient();
_client = new FlurlClient(httpClient);
Run Code Online (Sandbox Code Playgroud)
并使用所有 FlurlClient 方法/扩展。
但是后来我注意到 是否可以将 Furl.Http 与 OWIN TestServer 一起使用?其中描述了在 owin 实现中需要做更多的工作。
Asp.Net Core TestServer 的方法是否类似?还是简化了?
我在2天前安装了Visual Studio 2017社区版15.7.5,一切都是最新的,但ASP.Net Core的版本是2.0,我需要它是2.1.
我无法找到将其更新到2.1版的方法.我也搜索了互联网,但有一些方法可以升级项目而不是更新它.所以任何想法或帮助将不胜感激
asp.net-core-mvc .net-core asp.net-core asp.net-core-2.1 .net-core-2.1
我喜欢NLOG由于描述的多种原因 https://robertmccarter.com/switching-to-nlog 和
但是我考虑 https://github.com/ServiceStack/ServiceStack 和 https://nuget.org/packages/ServiceStack.Logging.NLog以保持通用接口和将来切换到其他提供商的能力.
是否有人知道使用ServiceStack.Logging.NLog而不是直接NLog调用的任何缺点/限制?
它会导致任何重要的性能下降吗?
直接调用NLog记录器时是否可以使用任何功能,但ServiceStack不支持?
asp.net-core ×2
c# ×2
.net-core ×1
asp.net ×1
c#-4.0 ×1
flurl ×1
logging ×1
methods ×1
nlog ×1
servicestack ×1