The problem is passing the parameter to the delegate. I would rather not have to write a managed wrapper for my unmanaged class if it can easily be avoided. Is there any way to do what I want? I have tried putting in __nogc in various parts of the array declaration but I can't get it to compile.
I have a design question and I am looking for a best way to implement it.
Say I have a method which returns a string e.g.
string str = MyMethod();
MyMethod returns a string from one of the predefined strings. Based on the return value I need to execute certain sequence of methods. I do not want to implement it using an ugly if-else statements, so what is my best bet to implement it. I am looking for something like auto dispatching based on return values. Also the number of predefined strings can go up in future, so I do not really want to touch the code everytime a new string is added.
I have thought of associative array's based solution. The array will store the string to method mapping and based on the return value the correct method will be invoked. But I am not sure if this is an elegant solution.
Can someone please guide me on how to go about for an elegant solution.
It sounds like you are asking about a "plug-in" implementation.
the correct method will be invoked.
Well that approach would be similar to the old C function pointer technique. OO concepts introduced "interfaces" which are preferable from a design standpoint. It is also referred to as Design by Contract[^]
Anyway a simplified version of this for a "plug in" implementation could go like this:
Design one or more interfaces (see Design by Contract). Each plug-in (class) will implement one or more of these interfaces. Along with the interfaces you design a "configuration" scheme for giving the application the required information about new classes that have been installed. Then you can leverage the System.Reflection classes to dynamically instantiate an object from it's text name (basically). Using this approach you can add new classes to an application by installing a new assembly and adding the requisite information to the applications configuration file.
do you know of the method in .NET 2005 that can help me work on config files?
in the config files, i need to pass string through..
basically, i need to write and read config files to store values in string.
PS:i dont know how to use your codes as i dont understand them, thanks for attaching them. (:
I think you should begin with finding out how message boards work.
First thing is to find the right message board, in this case you are in the wrong one.
This message board is only for C++/cli.
Second thing is that you never ever ask someone to do your homework.
With this said I think you should google a c tutorial or buy a book.