Professional IronPython


Adding the Required References to the Host language



Download 20,35 Mb.
Pdf ko'rish
bet328/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   324   325   326   327   328   329   330   331   ...   453
Adding the Required References to the Host language
You can perform a multitude of tasks with IronPython. In fact, later chapters in the book show 
how to perform tasks such as testing your static application code. IronPython really is quite flexible. 
However, most people will start by executing external scripts and only need a few of the namespaces 
in the IronPython assemblies to do it. The following 
using
statements provide everything needed to 
execute and manage most IronPython scripts.
using System; 
using IronPython.Hosting; 
using IronPython.Runtime; 
using Microsoft.Scripting.Hosting;
Understanding the Use of ScriptEngine
You have many options for working with IronPython scripts. This first example takes an approach 
that works fine for Visual Studio 2008 developers, as well as those using Visual Studio 2010. It doesn’t 
require anything fancy and it works reliably for most scripts. Ease and flexibility concerns aside, this 
isn’t the shortest technique for working with IronPython scripts. This is the Method1 approach to work-
ing with IronPython scripts — the technique that nearly everyone can use and it appears in Listing 15-2.
lISTINg 15-2: 
 Using the script engine to access the script
static void Main(string[] args)
{
// Create an engine to access IronPython.
ScriptEngine Eng = Python.CreateEngine();
// Describe where to load the script.
ScriptSource Source = Eng.CreateScriptSourceFromFile(“TestClass.py”);
// Obtain the default scope for executing the script.
ScriptScope Scope = Eng.CreateScope();
// Create an object for performing tasks with the script.
ObjectOperations Ops = Eng.CreateOperations();
// Create the class object.
Source.Execute(Scope);
// Obtain the class object.
Object CalcClass = Scope.GetVariable(“DoCalculations”);
// Create an instance of the class.
Object CalcObj = Ops.Invoke(CalcClass);
// Get the method you want to use from the class instance.
Object AddMe = Ops.GetMember(CalcObj, “DoAdd”);
// Perform the add.
Int32 Result = (Int32)Ops.Invoke(AddMe, 5, 10);
continues
548592c15.indd 313
2/25/10 9:45:55 AM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   324   325   326   327   328   329   330   331   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish