このSCALAコードは慣用的なC#でどのように見えますか?
-
30-09-2019 - |
質問
私たちが取り組んでいる.NETプロジェクトのXMPPを調査しながら、この本当に見栄えの良い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/communitivity/minimalscalaxmppcomponent/blob/master/src/org/communitivity/echoxmpp/main.scala)
俳優とパターンマッチングのものは、スケーラブルな方法でコンポーネントを書くのに非常に優れた方法のように見えます。私は成熟しているように見えるC#Actorsライブラリを見つけることができませんでした。学習axumはやり過ぎのようです。
これをC#で攻撃する正しい方法は何でしょうか? (もちろん、XMPP固有のコードを無視してください - 私は、俳優とパターンマッチングのC#バージョンがどのようになるかにもっと興味があります)。
所属していません StackOverflow