繁体   English   中英

自动完成的Lambda表达式(使用像函数参数一样的函数)(C#,Visual Studio 2019)

[英]Autocomplete lambda expression (when it used like functions parameter) (C#, Visual Studio 2019)

我无法让Development Studio用正确的数据代替lambda表达式作为被调用函数的参数。 这个怎么做?

我创建了一个可处理网络请求的类。 在此类中声明了三个委托,并且有一个向服务器发出请求的函数。 该函数的参数是:服务器命令和三个回调函数(代理)。 我在键盘上按了不同的组合,但没有一个组合允许自动替换lambda函数,因此我必须不断地用手填充所有内容。

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
        }
    }
}

这是我使用lambda-callback进行http请求的方式(有效):

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) =>
    {

    }
    );

如何强制Visual Studio(2017或2019)使用键盘组合粘贴功能lambda-param?

    (SimpleAnswer answer) =>
    {

    },
    (SimpleAnswer answer, string errorMsg) =>
    {

    }

如您所知,代码段不是一个好的解决方案,因为函数或http-class可以在任何项目中更改。

因此,我只看到一种解决方案:始终为类的实际版本更新自己的代码段。 我对这个问题的看法:

<?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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM