Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
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 16-Jan-13 5:33am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
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#[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 265
1 _Amy 235
2 Peter Leow 205
3 Andreas Gieriet 180
4 Shmuel Zang 120
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100