Load types(classes) from a Assembly(exe file) : Assembly Load « Assembly « C# / CSharp Tutorial






using System; 
 
class MyClass { 
  int x; 
  int y; 
 
  public MyClass(int i) { 
    Console.WriteLine("Constructing MyClass(int). "); 
    x = y = i;  
    show(); 
  } 
 
  public MyClass(int i, int j) { 
    Console.WriteLine("Constructing MyClass(int, int). "); 
    x = i; 
    y = 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("Inside set(int, int). "); 
    x = a; 
    y = b; 
    show(); 
  } 
 
  // Overload set. 
  public void set(double a, double b) { 
    Console.Write("Inside set(double, double). "); 
    x = (int) a; 
    y = (int) b; 
    show(); 
  } 
 
  public void show() { 
    Console.WriteLine("Values are x: {0}, y: {1}", x, y); 
  } 
} 
 
class AnotherClass { 
  string remark; 
 
  public AnotherClass(string str) { 
    remark = str; 
  } 
 
  public void show() { 
    Console.WriteLine(remark); 
  } 
} 
 
/////////////////////////////////////

using System; 
using System.Reflection; 
 
class MainClass { 
  public static void Main() { 
    int val; 
 
    Assembly asm = Assembly.LoadFrom("MyClasses.exe"); 
 
    Type[] alltypes = asm.GetTypes(); 
    foreach(Type temp in alltypes) 
      Console.WriteLine("Found: " + temp.Name); 
 
    Console.WriteLine(); 
 
  } 
}








12.4.Assembly Load
12.4.1.Assemblies
12.4.2.difference between Assembly.Load and Assembly.LoadFrom
12.4.3.Load types(classes) from a Assembly(exe file)
12.4.4.Load the System.Xml assembly using an AssemblyName
12.4.5.Create Type by Assembly qualifed type name
12.4.6.Late Binding
12.4.7.Assembly unloading
12.4.8.Dynamic assembly introspection
12.4.9.Deeper Reflection: Listing All the Types in an Assembly
12.4.10.Assembly Loader
12.4.11.GetManifestResourceStream