C# Networking and function/ctor signatures
Hi i was wondering what would be some of possible ways to get my program working like this:
1) Server sends command (that is function name/ object creator + arguments) 2) Client decodes what command is this - using some hash table of function id's etc
Problem is - if i know that the command is to create objectX and objectX constructor takes two arguments - for example int Z and float Y.
Now i know i must create objectX, but how do know what arguments i m开发者_Python百科ust read in to construct it? Im looking for fast ways to do this, also so that garbage generation is kept very low.
One way would be to just have one big case for each function or ctor, but im not big fan of "uber switch" approaches.
Any ideas?
You can do it with Activator.CreateInstance
. It has a constructor that takes a Type
and an array of objects. That should fit your neeeds. Read more about it here: http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx
Would a dependency injector like StructureMap or Ninject help?
http://structuremap.sourceforge.net/QuickStart.htm
http://ninject.org/
精彩评论