using System.Collections.Generic;
public string Identity { get; private set; }
public string Operation { get; private set; }
public Current(string identity, string operation)
public void IcePing(Ice.Current current)
Console.WriteLine("default ice_ping");
Dispatcher IceDefaultDispatcher()
return (Incoming inS, Current current) => IceDispatch(this, inS, current);
private static void IceD_IcePing(IObject servant, Ice.Incoming inS, Ice.Current current)
servant.IcePing(current);
public static void IceDispatch(IObject servant, Ice.Incoming inS, Ice.Current current)
if(current.Operation == "ice_ping")
IObject.IceD_IcePing(servant, inS, current);
Console.WriteLine("OperationNotExistException");
public delegate void Dispatcher(Incoming inS, Current current);
public class ObjectAdapter
public void Add(string identity, IObject servant, Dispatcher dispatcher = null)
_asm[identity] = (servant, dispatcher ?? servant.IceDefaultDispatcher());
public void AddDispatcher(string identity, Dispatcher dispatcher)
_asm[identity] = (null, dispatcher);
public IObject Find(string identity)
if(_asm.TryGetValue(identity, out var tuple))
var (servant, dispatcher) = tuple;
public Dispatcher FindDispacher(string identity)
if(_asm.TryGetValue(identity, out var tuple))
var (servant, dispatcher) = tuple;
public void Dispatch(Current current)
FindDispacher(current.Identity)(null, current);
private Dictionary<string, ValueTuple<IObject, Dispatcher>> _asm = new Dictionary<string, ValueTuple<IObject, Dispatcher>>();
public interface IMyInterface : Ice.IObject
public void MyOp(Ice.Current current);
Ice.Dispatcher Ice.IObject.IceDefaultDispatcher()
return (Ice.Incoming inS, Ice.Current current) => IMyInterface.IceDispatch(this, inS, current);
private static void IceD_MyOp(IMyInterface servant, Ice.Incoming inS, Ice.Current current)
public static void IceDispatch(IMyInterface servant, Ice.Incoming inS, Ice.Current current)
if(current.Operation == "my_op")
IMyInterface.IceD_MyOp(servant, inS, current);
Ice.IObject.IceDispatch(servant, inS, current);
public class MyInterface : IMyInterface
public void MyOp(Ice.Current current)
Console.WriteLine("MyOp");
public class MyInterface2 : IMyInterface
public void IcePing(Ice.Current current)
Console.WriteLine("MyIcePing");
public void MyOp(Ice.Current current)
Console.WriteLine("MyOp");
public static void Main()
var adapter = new Ice.ObjectAdapter();
adapter.Add("hello", new MyInterface());
adapter.Add("hello2", new MyInterface2());
var servant = new MyInterface2();
adapter.AddDispatcher("hello3", (Ice.Incoming inS, Ice.Current current) => IMyInterface.IceDispatch(servant, inS, current));
adapter.Dispatch(new Ice.Current("hello", "my_op"));
adapter.Dispatch(new Ice.Current("hello", "ice_ping"));
adapter.Dispatch(new Ice.Current("hello2", "ice_ping"));
adapter.Dispatch(new Ice.Current("hello3", "my_op"));