I can not get the development studio to substitute a lambda expression with the correct data as a parameter of the called function. How to do this?
I created a class that works with network requests. Three delegates are declared in this class and there is a function that makes a request to the server. The parameters of this function are: a command to the server and three callback functions (delegates). I pressed different combinations on the keyboard, but none of them allow substituting lambda functions automatically and I have to constantly fill everything with my hands.
http-manager:
namespace ProglotClientAdminPanel.managers
{
public delegate void RequestCompletedCallBack(SimpleAnswer answer);
public delegate void RequestSuccessCallback(SimpleAnswer answer);
public delegate void RequestErrorCallback(SimpleAnswer answer, string errorMsg);
public class ApiRequestHelperAsync
{
/// <summary>
/// send request
/// </summary>
/// <param name="simpleCommandIn">SimpleCommand - command model</param>
/// <param name="callBackIn">global callback</param>
/// <param name="successCallbackIn">success callback</param>
/// <param name="errorCallbackIn">error callback</param>
public void sendRequest(SimpleCommand simpleCommandIn,
RequestCompletedCallBack callBackIn = null,
RequestSuccessCallback successCallbackIn = null, RequestErrorCallback errorCallbackIn = null)
{
simpleCommand = simpleCommandIn;
callBack = callBackIn;
successCallback = successCallbackIn;
errorCallback = errorCallbackIn;
sendRequestToServer();//send http-request to server
}
}
}
This is how I make http-request with lambda-callback (it works):
SimpleCommand command = new SimpleCommand("saveStock");
command.addParam("org_id", user.org_id);
command.addParam("user_id", user.user_id);
command.addParam("stock", editableStock);
new ApiRequestHelperAsync().sendRequest(command,
null,
(SimpleAnswer answer) =>
{
},
(SimpleAnswer answer, string errorMsg) =>
{
}
);
How to force Visual Studio (2017 or 2019) to paste function lambda-param using keyboard combination?
(SimpleAnswer answer) =>
{
},
(SimpleAnswer answer, string errorMsg) =>
{
}
As you understand, code snippet is not good solution, because function or http-class may be changed at any project.
So, I see only one solution: always update own code snippets for actual versions of class. My variant for this question:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Simple API http-request (2 callbacks)</Title>
<Shortcut>httpLambded_2callbacks</Shortcut>
<Description>Make simple http-request with 2 lambda-callbacks</Description>
<Author>Lunev N.F.</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
new ApiRequestHelperAsync().sendRequest(command,
null,
(SimpleAnswer answer) =>
{
//on success
},
(SimpleAnswer answer, string errorMsg) =>
{
//on error
}
);
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.