以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  我想问下这种新式的c#语法,在Foxtable的vb.net里怎么写?我在js也经常见到和使用  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=159288)

--  作者:chen37280600
--  发布时间:2020/12/21 10:15:00
--  我想问下这种新式的c#语法,在Foxtable的vb.net里怎么写?我在js也经常见到和使用

①简单点的:
httpsv.AddWebSocketService<Chat> ("/ChatWithNyan", () => new Chat (" Nyan!"));
 
②高级点的:
wssv.AddWebSocketService<Chat> (
  "/Chat",
  () =>
    new Chat () {
      OriginValidator = val => {
          // Check the value of the Origin header, and return true if valid.
          Uri origin;
          return !val.IsNullOrEmpty ()
                 && Uri.TryCreate (val, UriKind.Absolute, out origin)
                 && origin.Host == "example.com";
        },
      CookiesValidator = (req, res) => {
          // Check the cookies in \'req\', and set the cookies to send to
          // the client with \'res\' if necessary.
          foreach (Cookie cookie in req) {
            cookie.Expired = true;
            res.Add (cookie);
          }

          return true; // If valid.
        }
    }
);

要想问红字这一堆,用平时的C#转vb代码工具,转不了的。还是说这种是C#独有的语法糖,vb已经被抛弃,不被微软照顾这种写法?

图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20201221101436.png
图片点击可在新窗口打开查看
[此贴子已经被作者于2020/12/21 10:18:20编辑过]

--  作者:有点蓝
--  发布时间:2020/12/21 10:19:00
--  
估计是代码不完整,转换不了

httpsv.AddWebSocketService(of Chat) ("/ChatWithNyan", function()  new Chat (" Nyan!"))

--  作者:chen37280600
--  发布时间:2020/12/21 13:27:00
--  
在github的websocket的案例代码看到的,应该不是代码不完整

https://github.com/sta/websocket-sharp/blob/master/Example2/Program.cs


图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看


--  作者:有点蓝
--  发布时间:2020/12/21 13:47:00
--  
我的意思是http://converter.telerik.com/这个网站需要相对完整的代码否则无法识别,比如一个完整的函数。

另外可能是使用了匿名函数,这个网站也不是完美的。

可以百匿名函数自己改改:https://www.baidu.com/baidu?word=vb.net+匿名函数