.


:




:

































 

 

 

 


Assembly, , Get Types () .




[ ] GetTypesO

, .

, . , . MyClasses. cs, .

// , MyClasses.cs.

Using System;

class MyClass { int x; int y;

public MyClass(int i) {

Console.WriteLine(" MyClass(int). "); x = = i;

Show ();

}

public MyClass(int i, int j) {

Console.WriteLine(" MyClass(int, int). "); x = i;

= j;

Show();

}

public int Sum() { return x+y;

}

public bool IsBetween(int i) {

if ((x < i) && (i < y)) return true;

else return false; \

}

public void Set(int a, int b) {

Console.Write(" Set(int, int). "); x = a;

= b;

Show();

}

// . Set.

public void Set(double a, double b) {

Console.Write(" Set(double, double). "); x = (int) a; = (int) b;

Show ();

}

public void Show() {

Console.WriteLine (" x: {0}, : {1}", x, );

}

}

class AnotherClass { string msg;

public AnotherClass(string str) { msg = str;

}

public void Show() {

Console.WriteLine(msg);

class Demo {

static void Main() {

Console.WriteLine(" .");

}

}

MyClass, . , AnotherClass Demo. , , , , . , MyClasses. . .

, MyClasses. . .

/* , . */

Using System;

Using System.Reflection;

class ReflectAssemblyDemo { static void Main() { int val;

// MyClasses.exe.

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

// , MyClasses.exe.

[] alltypes = asm.GetTypes(); foreach(Type temp in alltypes)

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

Console.WriteLine();

// , MyClass.

Type t = alltypes[0]; // Console.WriteLine(": " + t.Name);

// .

Constructorlnfo[] ci = t.GetConstructors();

Console.WriteLine(" : "); foreach(Constructorlnfo in ci) {

// .

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

// .

Parameterlnfo[] pi = .GetParameters(); for(int i=0; i < pi.Length; i++) {

Console.Write(pi[i].ParameterType.Name + " " + pi[i].Name);

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

}

Console.WriteLine (")");

}

Console.WriteLine ();

// , int x;

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

Parameterlnfo[] pi = ci[x].GetParameters(); if (pi.Length == 2) break;

}

if(x == ci.Length) {

Console.WriteLine(" ."); return;

}

Else

Console.WriteLine(" .\n");

// , object[] consargs = new object[2]; consargs[0] = 10; consargs[1] = 20;

object reflectOb = ci[x].Invoke(consargs);

Console.WriteLine("\ reflectOb."); Console.WriteLine();

MethodInfo[] mi = t.GetMethods();

// , foreach(Methodlnfo m in mi) {

// .

Parameterlnfo[] pi = m.GetParameters();

if(m.Name.CompareTo("Set")==0 &&

pi[0].ParameterType == typeof(int)) {

// Set(int, int). object[] args = new object[2]; args[0] = 9; args[l] = 18;





:


: 2016-12-03; !; : 467 |


:

:

! . .
==> ...

1542 - | 1331 -


© 2015-2024 lektsii.org - -

: 0.009 .