Professional IronPython


Testing the extension using IronPython



Download 20,35 Mb.
Pdf ko'rish
bet350/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   346   347   348   349   350   351   352   353   ...   453
 Testing the extension using IronPython
# Add a reference to the CLR
import clr
# Obtain access to the extension.
clr.AddReferenceToFile(‘Calcs.DLL’)
import Calcs
# Create an instance of the class and fill it with data.
Value1 = Calcs.Calcs(10)
# Print the original value, then decrement and increment it.
print ‘Original Value1 Content: ‘, Value1 
print ‘Value1 + 1: ‘, Value1.Inc() 
print ‘Value1 - 1: ‘, Value1.Dec()
# Create a second value and display it.
Value2 = Calcs.Calcs(5) 
print ‘\nOriginal Value2 Content: ‘, Value2
# Use the two values together in different ways.
print ‘\nValue1 + Value2 = ‘, Value1 + Value2
continues
548592c16.indd 335
2/24/10 12:49:23 PM
www.finebook.ir


336

CHAPTER 16
ExtEnding ironPython Using C#
print ‘Value1 - Value2 = ‘, Value1 - Value2
print ‘Value1 * Value2 = ‘, Value1 * Value2
print ‘Value1 / Value2 = ‘, Value1 / Value2
# Pause after the debug session.
raw_input(‘\nPress any key to continue...’)
The example begins by importing support for the Common Language Runtime (CLR). It then uses the 
AddReferenceToFile()
method to reference the 
Calcs.DLL
file and imports the code into IronPython. 
These steps are similar to those that you used to test the DLL initially.
The next step is to create an instance of the 
Calcs
class, 
Value1
. The code references 
Calcs
twice — 
once for the namespace and a second time for the class itself. The next few code steps display the 
value of 
Value1
and show how to use the 
Inc()
and 
Dec()
methods. If you set 
Value1
equal to 
the output of 
Inc()
or 
Dec()
, it truly would increment or decrement the value of 
Value1
. Because 
IronPython doesn’t support the 
++
operator, however, you can’t use the 
++
operator in your exten-
sion. On the other hand, you could implement the 
+=
and 
-=
operators.
You can’t really test binary operators without a second variable, so the code creates a second 
instance of 
Calcs

Value2
. The example then shows how the 
+

-

*
, and 
/
operators work. 
Figure 16-7 shows the output from this example.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   346   347   348   349   350   351   352   353   ...   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