在研究XMPP的.NET项目时,我遇到了这个非常漂亮的Scala代码:

object Main {

  /**
   * @param args the command line arguments
   */
  def main(args: Array[String]) :Unit = {
      new XMPPComponent(
        new ComponentConfig() {
            def secret() : String = { "secret.goes.here" }
            def server() : String = { "communitivity.com" }
            def subdomain() : String = { "weather" }
            def name() : String = { "US Weather" }
            def description() : String = { "Weather component that also supported SPARQL/XMPP" }
        },
       actor {
        loop {
            react {
                case (pkt:Packet, out : Actor) =>
                    Console.println("Received packet...\n"+pkt.toXML)
                    pkt match {
                        case message:Message =>
                            val reply  = new Message()
                            reply.setTo(message.getFrom())
                            reply.setFrom(message.getTo())
                            reply.setType(message.getType())
                            reply.setThread(message.getThread())
                            reply.setBody("Received '"+message.getBody()+"', tyvm")
                            out ! reply
                        case _ =>
                            Console.println("Received something other than Message")
                    }
                 case _ =>
                    Console.println("Received something other than (Packet, actor)")
            }
        }
       }
    ).start
  }
}

(这是从 http://github.com/communitivitive/minimalscalaxmppcomponent/blob/master/src/org/communitivitivity/echoxmpp/main.scala)

演员和图案匹配的东西看起来像是以可扩展方式编写组件的一种非常好的方式。我找不到任何看起来很成熟的C#演员库,学习斧头看起来像是过分的。

在C#中攻击它的正确方法是什么? (当然,忽略XMPP特定的代码 - 我对C#版本的演员和模式匹配的样子更感兴趣)。

有帮助吗?

解决方案

有类似的演员图书馆可用于.NET参见 retlang 一个,也 F#代理 相似。

也看到这个 问题.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top