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 bool IceDispatch(IObject servant, Ice.Incoming inS, Ice.Current current)
if(current.Operation == "ice_ping")
IObject.IceD_IcePing(servant, inS, current);
public delegate bool 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)
if(!FindDispacher(current.Identity)(null, current))
Console.WriteLine("OperationNotExist");
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 bool IceDispatch(IMyInterface servant, Ice.Incoming inS, Ice.Current current)
if(current.Operation == "my_op")
IceD_MyOp(servant, inS, current);
else if(!Ice.IObject.IceDispatch(servant, inS, current))
public interface IMyInterface2 : Ice.IObject
public void MyOp2(Ice.Current current);
Ice.Dispatcher Ice.IObject.IceDefaultDispatcher()
return (Ice.Incoming inS, Ice.Current current) => IMyInterface2.IceDispatch(this, inS, current);
private static void IceD_MyOp2(IMyInterface2 servant, Ice.Incoming inS, Ice.Current current)
public static bool IceDispatch(IMyInterface2 servant, Ice.Incoming inS, Ice.Current current)
if(current.Operation == "my_op2")
IceD_MyOp2(servant, inS, current);
else if(!Ice.IObject.IceDispatch(servant, inS, current))
public interface IMyInterface3 : IMyInterface, IMyInterface2
public void MyOp3(Ice.Current current);
Ice.Dispatcher Ice.IObject.IceDefaultDispatcher()
return (Ice.Incoming inS, Ice.Current current) => IMyInterface3.IceDispatch(this, inS, current);
private static void IceD_MyOp3(IMyInterface3 servant, Ice.Incoming inS, Ice.Current current)
public static bool IceDispatch(IMyInterface3 servant, Ice.Incoming inS, Ice.Current current)
if(current.Operation == "my_op3")
IceD_MyOp3(servant, inS, current);
else if(!IMyInterface.IceDispatch(servant, inS, current) &&
!IMyInterface2.IceDispatch(servant, inS, current))
public class MyInterface : IMyInterface
public void MyOp(Ice.Current current)
Console.WriteLine("MyOp");
public class MyInterface2 : IMyInterface2
public void IcePing(Ice.Current current)
Console.WriteLine("MyIcePing");
public void MyOp2(Ice.Current current)
Console.WriteLine("MyOp2");
public class MyInterface3 : IMyInterface3
public void IcePing(Ice.Current current)
Console.WriteLine("ice_ping3");
public void MyOp(Ice.Current current)
Console.WriteLine("MyOp");
public void MyOp2(Ice.Current current)
Console.WriteLine("MyOp2");
public void MyOp3(Ice.Current current)
Console.WriteLine("MyOp3");
public static void Main()
var adapter = new Ice.ObjectAdapter();
adapter.Add("hello", new MyInterface());
adapter.Add("hello2", new MyInterface2());
adapter.Add("hello3", new MyInterface3());
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("hello2", "my_op2"));
adapter.Dispatch(new Ice.Current("hello3", "ice_ping"));
adapter.Dispatch(new Ice.Current("hello3", "my_op"));
adapter.Dispatch(new Ice.Current("hello3", "my_op2"));
adapter.Dispatch(new Ice.Current("hello3", "my_op3"));