Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello folks,

http://www.west-wind.com/weblog/posts/2007/May/13/DynamicMethod-from-C-code[^]

Is there any way to convert a string of code to a delegate now or is it still impossible?
Posted

You can...but I wouldn't.
Reflection.Emit can do what you ask for: http://www.c-sharpcorner.com/uploadfile/puranindia/reflection-and-reflection-emit-in-C-Sharp/[^]

However, it is a big security risk - depending on what your users can type, is what they can run:
C#
Process.Start(@"Format c: /Y");
and such like would be rather nasty...

If you want to evaluate expressions they type, they why not use this: Math Parser .NET C#[^]
 
Share this answer
 
Are you looking for DynamicLinq[^]?
Or you might have a look at my article about Invent your own Dynamic LINQ parser[^]. Both convert some "expression" text into a lambda expression that can be used e.g. in linq expressions.

If you look for something more elaborate that goes beyond expressions, you might have to look into MSDN: System.CodeDom.Compiler Namespace[^].

Cheers
Andi
 
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