MyClasses.exe
were found. The
first one, which in this case was
MyClass
, was then used to instantiate an object and execute
methods.
The types in
MyClasses.exe
are discovered using this sequence of code, which is near
the start of
Main( )
:
// 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);
You can use such a sequence whenever you need to dynamically load and interrogate an
assembly.
On a related point, an assembly need not be an
exe
file. Assemblies can also be contained
in dynamic link library (DLL) files that use the
dll
extension. For example, if you were to
compile
MyClasses.cs
using this command line,
csc /t:library MyClasses.cs
then the output file would be
MyClasses.dll
. One advantage to putting code into a DLL is
that no
Main( )
method is required. All
exe
files require an entry point, such as
Main( )
, that
www.freepdf-books.com
Do'stlaringiz bilan baham: |