smartcaveman / runsharp-google-export

Automatically exported from code.google.com/p/runsharp
MIT License
0 stars 0 forks source link

ILGenerator.BeginScope is not supproted on DynamicMethod #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If you try to create dynamic method with scopes (in my case exception 
handling) RunSharp tries to create new scope, but according to http://
msdn.microsoft.com/en-us/library/
system.reflection.emit.ilgenerator.beginscope.aspx?ppud=4 (remarks 
section) scopes aren't supported on Dynamic methods, this leads to 
NotSupportedException.

Here is The sample code:

        static void DynamicMethodExamples()
        {
            DynamicMethodGen dmg = DynamicMethodGen.Static
(typeof(Program)).Method(typeof(void)).Parameter(typeof(string), "name");
            CodeGen g = dmg.GetCode();
            g.Try();
            g.WriteLine("Hello {0}!", dmg.GetCode().Arg
("name"));
            g.Local(typeof(string),"value");//<<<<<HERE throws 
exception
            g.CatchAll();
            g.WriteLine("error");
            g.End();

            DynamicMethod dm = dmg.GetCompletedDynamicMethod
(true);
            // reflection-style invocation
            dm.Invoke(null, new object[] { "Dynamic Method" });

            // delegate invocation
            Action<string> hello = 
(Action<string>)dm.CreateDelegate(typeof(Action<string>));
            hello("Delegate");
        }

Original issue reported on code.google.com by ladislav...@seznam.cz on 29 Dec 2009 at 7:40

GoogleCodeExporter commented 9 years ago

Original comment by StefanSi...@gmail.com on 15 Jan 2010 at 7:41

GoogleCodeExporter commented 9 years ago

Original comment by StefanSi...@gmail.com on 15 Jan 2010 at 7:42

GoogleCodeExporter commented 9 years ago
Issue 18 has been merged into this issue.

Original comment by StefanSi...@gmail.com on 20 Aug 2010 at 8:55

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 4a1e9db06e.

Original comment by StefanSi...@gmail.com on 22 Aug 2010 at 9:25