C# 0 The Complete Reference


MyClass , which we have been using in the previous examples. It also  adds a second class called  AnotherClass



Download 4,07 Mb.
Pdf ko'rish
bet599/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   595   596   597   598   599   600   601   602   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

MyClass

, which we have been using in the previous examples. It also 

adds a second class called 

AnotherClass

 and a third class called 



Demo

. Thus, the assembly 

www.freepdf-books.com



478

 

P a r t   I :  



T h e   C #   L a n g u a g e

produced by this program will contain three classes. Next, compile this file so the file 



MyClasses.exe

 is produced. This is the assembly that will be interrogated.

The program that will discover information about 

MyClasses.exe

 is shown here. Enter 

it at this time.

/* Locate an assembly, determine types, and create

   an object using reflection. */

using System;

using System.Reflection;

class ReflectAssemblyDemo {

  static void Main() {

    int val;

    // Load the MyClasses.exe assembly.

    Assembly asm = Assembly.LoadFrom("MyClasses.exe");

    // Discover what types MyClasses.exe contains.

    Type[] alltypes = asm.GetTypes();

    foreach(Type temp in alltypes)

      Console.WriteLine("Found: " + temp.Name);

    Console.WriteLine();

    // Use the first type, which is MyClass in this case.

    Type t = alltypes[0]; // use first class found

    Console.WriteLine("Using: " + t.Name);

    // Obtain constructor info.

    ConstructorInfo[] ci = t.GetConstructors();

    Console.WriteLine("Available constructors: ");

    foreach(ConstructorInfo c in ci) {

      // Display return type and name.

      Console.Write("   " + t.Name + "(");

      // Display parameters.

      ParameterInfo[] pi = c.GetParameters();

      for(int i=0; i < pi.Length; i++) {

        Console.Write(pi[i].ParameterType.Name +

                      " " + pi[i].Name);

        if(i+1 < pi.Length) Console.Write(", ");

      }

      Console.WriteLine(")");

    }

    Console.WriteLine();



    // Find matching constructor.

    int x;

    for(x=0; x < ci.Length; x++) {

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   595   596   597   598   599   600   601   602   ...   1096




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