My guess is it depends on how often you'll be doing this and how many 
iterations you'll be running - or if performance is an issue for you at all.  
The overhead of invoking the C# compiler is going to be much greater than 
asking IronPython to generate some new code in process.  But the C# code is 
also going to run much faster.  So depending on if you're doing compilations a 
lot and how long the generated code one way may be better than the other.  
Another consideration is the amount of compilations you'll be doing:  
IronPython will compile the code as DynamicMethod's so its collectible by the 
GC but the C# generated code will end up in an assembly which requires an app 
domain unload to go away (which means creating app domains, getting the 
isolation right, etc...).

If none of those are issues for you then I would suggest personal preference of 
which one you like more, and which API you want to interact w/ to create the 
code - e.g. CodeDom can be a little verbose but with Python you'll be building 
the strings yourself.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of sms rku
Sent: Monday, August 06, 2007 10:05 PM
To: Discussion of IronPython
Subject: Re: [IronPython] C# and IronPython

Thanks Dino,
In similar lines, I can also call functions from assembly, I guess...

I have read some articles related to CodeDom, using which we can compile and 
run code(C# or VB.NET<http://VB.NET>) at runtime.
Which one of these two (using CodeDom OR using IronPython) is the better 
approach if the requirement is to
     1. Use loops like for, while  etc -i,e call methods in a loop in the script
     2. use script occasionally, that means scripting is not the feature that 
is used regularly by the user of the application

-Thanks
sms




On 8/6/07, Dino Viehland <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:

Yes, as long as the class is also public.  You just need to start ipy.exe in 
the directory where your exe's at and then do:



import clr

clr.AddReference('MyApplication')

from MyApplicationsNamespace import MyApplicationsClass  # if it's in a 
particular namespace

                or

import MyApplicationsClass # if it's in the global namespace

MyApplicationsClass.Main('arg1', 'arg2', 'arg3')

                Or

MyApplicationsClass.SomeOtherMethod()

                Or

x = MyApplicationsClass()

x.SomeInstanceMethod()





From: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> [mailto:[EMAIL 
PROTECTED]<mailto:[EMAIL PROTECTED]>] On Behalf Of sms rku
Sent: Sunday, August 05, 2007 10:03 PM
To: users@lists.ironpython.com<mailto:users@lists.ironpython.com>
Subject: [IronPython] C# and IronPython



I am very new to Python and IronPython.

Could you please let me know if it is possible to

Make my application [.exe] that has a static Main method and 3 other public 
methods defined in a class to be accessed from IronPython script?

i.e, Will I be able to create instance of the class from IronPython script?
      Will I be able to call the public methods from the script?

and also, is it possible to call the main function from the script?       [ i.e 
run my application]

If yes, could you please tell me how it can be done?

Thanks in advance
sms

_______________________________________________
Users mailing list
Users@lists.ironpython.com<mailto:Users@lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to