c# - How to use a variable as a method name using dynamic objects -
in signalr there public property defined in hubconnectioncontext such:
public dynamic { get; set; } this enables users call like: all.somemethodname(); brilliant.
i call using incoming parameter in function. how can this?
as in: all.<my variable method name>();
is there way of doing this?
thanks
edit example:
public void acceptsignal(string methodtocall, string msg) { clients.all.somemethod(msg); // works clients.all.<methodtocall>(msg); // not work (but to!) }
while love fun reflection answers, there's simpler , faster way invoke client hub methods using string method name.
clients.all, clients.others, clients.caller, clients.allexcept(connectionids), clients.group(groupname), clients.othersingrouop(groupname), , clients.client(connectionid) dynamic objects, implement iclientproxy interface.
you can cast of these dynamic objects iclientproxy, , call invoke(methodname, args...):
public void acceptsignal(string methodtocall, string msg) { iclientproxy proxy = clients.all; proxy.invoke(methodtocall, msg); }
Comments
Post a Comment