Professional IronPython


Interacting with .NET Framework Elements



Download 20,35 Mb.
Pdf ko'rish
bet146/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   142   143   144   145   146   147   148   149   ...   453
Interacting with .NET Framework Elements
 

 
129
print ThisRef
# Access a specific assembly and display more information about it.
ThisRef = clr.References[2] 
print ‘\nFull Name of System.Xml:’ 
print ThisRef.FullName
# Display the referenced assemblies. 
print ‘\nReferenced Assemblies:’ 
for Reference in ThisRef.GetReferencedAssemblies():
print Reference.ToString()
# Display the assembly attributes. 
print ‘\nAttributes:’ 
for AnAttribute in ThisRef.GetCustomAttributes(type(ThisRef)):
print AnAttribute.ToString()
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
The code begins by importing 
sys
and adding the .NET Framework 2.0 path to 
sys.path
. Adding 
just the path you need tends to reduce the risk of importing the wrong assembly. Even so, you want 
to verify that you’re using the right assembly, especially when the code is running on another system.
The next step is to import 
clr
. This module provides the features required to interact with the 
assemblies. The next few lines of code import 
System
and 
System.Xml
so that you can see a
number of assemblies in IronPython. Notice that the 
System.Xml
import requires use of the
clr.AddReference()
method.
At this point, the example obtains the list of loaded assemblies from the 
clr.References
property 
and displays them onscreen using a 
for
loop. Figure 7-11 shows the list of assemblies for this example. 
Notice that the first assembly is 
mscorlib
, which always loads.
You can drill down into an assembly as far as you want. The example continues by working with 
the 
System.Xml
assembly. As a first step, the code displays the full name of the assembly. Using 
string manipulation, you can obtain the assembly name, version, culture, and public key token.
When creating an installation program, you often need to know the list of referenced
assemblies. The next portion of application code shows how to perform this task using the 
ThisRef 
.GetReferencedAssemblies()
method. The output includes the same four pieces of information as 
the assembly information, so you know precisely which assemblies to include with your application.
Some developers also want to know about attributes assigned to an assembly. The 
ThisRef 
.GetCustomAttributes(type(ThisRef))
method call obtains this information. You must provide 
the type of the assembly you want to interact with. Notice that the example uses the Python 
type()
function, rather than a .NET equivalent. In some situations, you mix .NET and Python code to 
obtain a desired result. The code shows how to use a loop to obtain the list of attributes. Most 
assemblies include a wealth of attributes (some inherited). A developer might need to know some of 
these attributes, such as 
System.Security.Permissions.SecurityPermissionAttribute
(which 
provides security information about the assembly), to create a functional application.
548592c07.indd 129
2/25/10 9:44:29 AM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   142   143   144   145   146   147   148   149   ...   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