Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Created July 20, 2009 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyZhao/150216 to your computer and use it in GitHub Desktop.
Save JeffreyZhao/150216 to your computer and use it in GitHub Desktop.
namespace Test
{
using System;
using System.Collections.Generic;
using ActorLite;
public interface IPersonHandler
{
void Chat(Person another, Topic topic);
void Eat(Restaurant restaurant);
void Work(Person reportTo, Job job);
}
public class Person : Actor<Action<IPersonHandler>>, IPersonHandler
{
public string Name { get; set; }
protected override void Receive(Action<IPersonHandler> message) { message(this); }
#region IPersonHandler Members
void IPersonHandler.Chat(Person another, Topic topic)
{
Console.WriteLine("[{0}] 正在和[{1}] 谈论[{2}].", this.Name, another.Name, topic);
const string exitContent = "烦不烦,天天讨论天气,拜拜!!!!";
if (topic.Content == exitContent)
{
this.Exit();
}
else
{
another.Post(h => h.Chat(this, new Topic { Content = exitContent }));
}
}
void IPersonHandler.Eat(Restaurant restaurant)
{
Console.WriteLine("[{0}] 正在[{1}] 的 酒店就餐.");
}
void IPersonHandler.Work(Person reportTo, Job job)
{
Console.WriteLine("[{0}] 正在为他的上级[{1}] 做[{2}].");
}
#endregion
}
static class Program
{
static void Main(string[] args)
{
var zhangSan = new Person { Name = "张三" };
var liSi = new Person { Name = "李四" };
var wangWu = new Person { Name = "王五" };
zhangSan.Post(h => h.Chat(liSi, new Topic { Content = "今天天气也太热了,真受不了。。。。" });
wangWu.Post(h => h.Eat(new Restaurant()));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment