Click here to Skip to main content
15,884,099 members
Home / Discussions / C#
   

C#

 
GeneralMaximum value of an array Pin
crushinghellhammer30-Jan-04 9:37
crushinghellhammer30-Jan-04 9:37 
GeneralRe: Maximum value of an array Pin
Heath Stewart30-Jan-04 10:05
protectorHeath Stewart30-Jan-04 10:05 
GeneralRe: Maximum value of an array Pin
crushinghellhammer30-Jan-04 11:19
crushinghellhammer30-Jan-04 11:19 
GeneralRe: Maximum value of an array Pin
Heath Stewart30-Jan-04 11:36
protectorHeath Stewart30-Jan-04 11:36 
GeneralRe: Maximum value of an array Pin
crushinghellhammer30-Jan-04 11:59
crushinghellhammer30-Jan-04 11:59 
GeneralRe: Maximum value of an array Pin
Heath Stewart30-Jan-04 12:03
protectorHeath Stewart30-Jan-04 12:03 
Generalconsuming a class defined in another assembly Pin
godzooky30-Jan-04 8:56
godzooky30-Jan-04 8:56 
GeneralRe: consuming a class defined in another assembly Pin
Heath Stewart30-Jan-04 10:13
protectorHeath Stewart30-Jan-04 10:13 
See Type.GetType and Activator.CreateInstance for one way. There are many ways to do this. Lets say you have something like this:
App.exe:
public abstract BaseClass {...}
 
Lib.dll
public MyClass1 : BaseClass {...}
In App.exe, you can do something like this:
Type t = Type.GetType("MyClass1, lib.dll");
BaseClass bc = (BaseClass)Activator.CreateInstance(t);
If the first statement can't find the assembly (i.e., it's not in the same directory, in the GAC, or configured with a private path or binding path in your App.exe.config file), a TypeLoadException is thrown. If the instance can't be created, a number of exceptions might be thrown depending on what the problem is (see the documentation for the Activator.CreateInstance overloaded method in the .NET Framework SDK for more information).

The only problem is that VS.NET won't let you reference a .exe assembly so you will have to compile this on the command line, which isn't hard. Since MyClass1 derives from BaseClass, which is in a .exe assembly, you can't reference it. The compiler doesn't care, it's just that VS.NET won't let you. Frown | :(

Further, you might consider using a configuration file (.config) so that you can change the types or have a plug-in type system. There are many articles here on CP that cover this, and discuss other ways to load and instantiate a Type by name. Try this search: http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=plugins[^].

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: consuming a class defined in another assembly Pin
godzooky30-Jan-04 10:39
godzooky30-Jan-04 10:39 
GeneralRe: consuming a class defined in another assembly Pin
Heath Stewart30-Jan-04 10:46
protectorHeath Stewart30-Jan-04 10:46 
GeneralRe: consuming a class defined in another assembly Pin
Nick Parker30-Jan-04 11:19
protectorNick Parker30-Jan-04 11:19 
GeneralRe: consuming a class defined in another assembly Pin
godzooky30-Jan-04 15:41
godzooky30-Jan-04 15:41 
GeneralWindows Services using C# Pin
Todd J Christensen30-Jan-04 8:19
sussTodd J Christensen30-Jan-04 8:19 
GeneralRe: Windows Services using C# Pin
David R. Tosi30-Jan-04 8:52
David R. Tosi30-Jan-04 8:52 
GeneralRe: Windows Services using C# Pin
Member 64105530-Jan-04 11:29
Member 64105530-Jan-04 11:29 
GeneralComponents: Design-Time support for properties Pin
UB30-Jan-04 6:51
UB30-Jan-04 6:51 
GeneralRe: Components: Design-Time support for properties Pin
Heath Stewart30-Jan-04 9:57
protectorHeath Stewart30-Jan-04 9:57 
GeneralRe: Components: Design-Time support for properties Pin
UB1-Feb-04 6:13
UB1-Feb-04 6:13 
GeneralC# controls in W2K... Pin
EyeOfTheSky30-Jan-04 5:58
EyeOfTheSky30-Jan-04 5:58 
GeneralRe: C# controls in W2K... Pin
Tom Larsen30-Jan-04 6:25
Tom Larsen30-Jan-04 6:25 
GeneralRe: C# controls in W2K... Pin
EyeOfTheSky30-Jan-04 7:17
EyeOfTheSky30-Jan-04 7:17 
GeneralRe: C# controls in W2K... Pin
Heath Stewart30-Jan-04 9:53
protectorHeath Stewart30-Jan-04 9:53 
GeneralRe: C# controls in W2K... Pin
Nick Parker30-Jan-04 11:09
protectorNick Parker30-Jan-04 11:09 
General2D Arrays, something strange Pin
bouli30-Jan-04 5:36
bouli30-Jan-04 5:36 
GeneralRe: 2D Arrays, something strange Pin
Heath Stewart30-Jan-04 9:49
protectorHeath Stewart30-Jan-04 9:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.