Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to define 10 functions like this:
SetData1()
SetData2()
SetData3()
SetData4()
SetData5()
SetData6()
SetData7()
SetData8()
SetData9()
SetData10()

How can I define the function dynamically in run-time instead of hardwiring it?

Thanks
Posted
Comments
Zoltán Zörgő 24-Jul-12 13:22pm    
It is most unlikely, that something like this is needed - although it can be achieved with runtime compilation. You probably need to rethink the logic of your program a little bit. How exactly do you want to use these methods?
Sergey Alexandrovich Kryukov 24-Jul-12 14:27pm    
Agree with Zoltán. I don't think you understand what you really need. Before asking how to do that, explain your ultimate goals, to get a really useful advice.
--SA
lewax00 24-Jul-12 14:37pm    
If you give us some more context we might be able to help you, you haven't really provided enough information to give you a clear answer (and honestly, it looks like you might be trying to go about this, whatever it is, in the wrong way).

As Zoltan says, runtime compilation will let you do this, but I also suspect that this is probably a major design problem if you need to do this on a regular basis.

Why do you think you need this? Do you need to declare the function body at runtime?

I would probably look at trying to use delegates instead of runtime compilation. If you can, that would be a much, much easier solution to maintain (and debug!)
 
Share this answer
 
You should be able to use Roslyn. The following has some information on using Roslyn for this: Using Roslyn ScriptEngine for a ValueConverter to process user input[^]. Since I do not know details, cannot know if this will help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900