Click here to Skip to main content
16,005,181 members
Home / Discussions / C#
   

C#

 
GeneralRe: Lock question Pin
Guffa21-Aug-05 1:23
Guffa21-Aug-05 1:23 
GeneralRe: Lock question Pin
Steve Messer21-Aug-05 2:43
Steve Messer21-Aug-05 2:43 
GeneralGDI+ Paths and Regions Pin
mpastchenko19-Aug-05 8:39
mpastchenko19-Aug-05 8:39 
GeneralRe: GDI+ Paths and Regions Pin
mpastchenko19-Aug-05 11:37
mpastchenko19-Aug-05 11:37 
GeneralLabel Graph Tick Mark Axis, Mistake Pin
...---...19-Aug-05 7:09
...---...19-Aug-05 7:09 
GeneralRe: Label Graph Tick Mark Axis, Mistake Pin
...---...19-Aug-05 7:13
...---...19-Aug-05 7:13 
GeneralRe: Label Graph Tick Mark Axis, Mistake Pin
Guffa19-Aug-05 7:17
Guffa19-Aug-05 7:17 
QuestionHow2 assign specific class type to generic object type? Pin
Dennis McMahon19-Aug-05 7:08
Dennis McMahon19-Aug-05 7:08 
I have a situation where I have three separate C# class objects that all have the same properties and methods so their signatures are the same in all respects except for the class name (I am writing a code generator for personal use with each class representing a different design pattern).
There is also a core class which operates as a control point to call each class depending on which design pattern is chosen. The challenge I have is that it would be extremely cumbersome and complex in the control class to populate the many properties and call the many methods separately for each design pattern class so I was attempting to declare a generic object type first, instantiate the proper pattern class inside a switch block, assign the instantiated pattern class to the generic object type outside of the switch block, and finally populate all the necessary properties and call all the necessary methods using the generic object type class.
The result in many different attempts to do this always ends up with the compiler returning an error message saying the generic object type class does not contain the properties or methods specifed and I am looking for a way to make this happen.

Psuedo-code for what I am trying to do:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Declare generic object type
object cNetPattern;

// Determine design pattern requested
switch(m_iNETDesignPattern)
{
case (int)eNETDesignPattern.TDSTraversal:
// Instantiate TDS Traversal design pattern class 'clsPattern_1' here
break;
case (int)eNETDesignPattern.Collection:
// Instantiate Collections design pattern class 'clsPattern_2' here
break;
case (int)eNETDesignPattern.ClassProvider:
// Instantiate Class Provider design pattern class 'clsPattern_3' here
break;
}

// Assign specific class type object to generic object type
cNetPattern = clsPattern_n; // Where 'n' is the specific pattern class object instantiated above

// Populate properties and call methods
cNetPattern.bProperty1 = m_bProperty1;
cNetPattern.Method1();
...many, many more properties and methods

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

NOTE: As mentioned all three specific design patterns have the same property and method signatures.

Any help would be grealy appreciated!


Dennis M.
AnswerRe: How2 assign specific class type to generic object type? Pin
AndrewJMarshall19-Aug-05 7:36
AndrewJMarshall19-Aug-05 7:36 
GeneralRe: How2 assign specific class type to generic object type? Pin
Dennis McMahon19-Aug-05 8:01
Dennis McMahon19-Aug-05 8:01 
GeneralDataGrid bounded to a DataTable with composite key. Pin
miah alom19-Aug-05 6:55
miah alom19-Aug-05 6:55 
GeneralRe: DataGrid bounded to a DataTable with composite key. Pin
rudy.net19-Aug-05 13:35
rudy.net19-Aug-05 13:35 
GeneralRe: DataGrid bounded to a DataTable with composite key. Pin
miah alom21-Aug-05 6:01
miah alom21-Aug-05 6:01 
QuestionAUTO UPDATE?? Pin
cyrus_thevirus19-Aug-05 5:27
cyrus_thevirus19-Aug-05 5:27 
AnswerRe: AUTO UPDATE?? Pin
Mohamad Al Husseiny19-Aug-05 6:19
Mohamad Al Husseiny19-Aug-05 6:19 
GeneralRe: AUTO UPDATE?? Pin
cyrus_thevirus19-Aug-05 6:41
cyrus_thevirus19-Aug-05 6:41 
GeneralRe: AUTO UPDATE?? Pin
ekynox19-Aug-05 17:01
ekynox19-Aug-05 17:01 
GeneralFile Copy from remote server Pin
NitinR19-Aug-05 5:19
NitinR19-Aug-05 5:19 
GeneralRe: File Copy from remote server Pin
| Muhammad Waqas Butt |19-Aug-05 5:40
professional| Muhammad Waqas Butt |19-Aug-05 5:40 
GeneralGarbage Collection Issue Pin
MarkMokris19-Aug-05 4:43
MarkMokris19-Aug-05 4:43 
GeneralRe: Garbage Collection Issue Pin
Dan Neely19-Aug-05 4:56
Dan Neely19-Aug-05 4:56 
GeneralRe: Garbage Collection Issue Pin
MarkMokris19-Aug-05 6:00
MarkMokris19-Aug-05 6:00 
GeneralRe: Garbage Collection Issue Pin
S. Senthil Kumar19-Aug-05 5:52
S. Senthil Kumar19-Aug-05 5:52 
GeneralRe: Garbage Collection Issue Pin
MarkMokris19-Aug-05 10:19
MarkMokris19-Aug-05 10:19 
Generalstupid question :$ Pin
f_n_d19-Aug-05 4:41
f_n_d19-Aug-05 4:41 

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.