PC Review


Reply
Thread Tools Rate Thread

dynamic classes

 
 
=?Utf-8?B?S2llcmFu?=
Guest
Posts: n/a
 
      25th May 2004
Hi

I have 2 classes, layout1 and layout2, both return different table layouts

In my controlling program I create one of these tables using

Table myTable = new layout1

I need to parameterise the 'layout1' part of this statement, so I can choose a different layout at runtime. Is this possible or is there a better way of doing this

Thank
Kieran
 
Reply With Quote
 
 
 
 
Niki Estner
Guest
Posts: n/a
 
      25th May 2004
Table myTable;
if (...) myTable = new layout1 else myTable = new layout2;

I'm not really sure if I got your question...

Niki

"Kieran" <(E-Mail Removed)> wrote in
news:B3F9BCC2-F9E4-46AA-BF73-(E-Mail Removed)...
> Hi,
>
> I have 2 classes, layout1 and layout2, both return different table

layouts.
>
> In my controlling program I create one of these tables using:
>
> Table myTable = new layout1;
>
> I need to parameterise the 'layout1' part of this statement, so I can

choose a different layout at runtime. Is this possible or is there a better
way of doing this?
>
> Thanks
> Kieran



 
Reply With Quote
 
=?Utf-8?B?S2llcmFu?=
Guest
Posts: n/a
 
      26th May 2004
Hi

Thanks for your reply, I was hoping though to feed in the class name though, e.

string myClass = 'layout1

Table myTable = new myClas

I know the above wont work but I hope this explains what I'm trying to do. I'm effectively trying to decide the class to use at runtime?

Thank
Kieran
 
Reply With Quote
 
Niki Estner
Guest
Posts: n/a
 
      26th May 2004
Ok, that explains at least what you want to do: You can use
Activator.CreateInstance("name-of-your-assembly", "layout1").Unwrap(), to
create an instance of a class by its name.

However, the more "type-safe" approach would be something like:

Type myClass = typeof(layout1);
....
Table myTable = Activator.CreateInstance(myClass);

Or you could implement IClonable in all your classes, and write:

ICloneable myClass = new layout1;
....
Table myTable = myClass.Clone();

(I think this one is GoF pattern, but don't remember it's name)

Niki

"Kieran" <(E-Mail Removed)> wrote in
news:67EF04EF-1F01-4B4D-9FAB-(E-Mail Removed)...
> Hi,
>
> Thanks for your reply, I was hoping though to feed in the class name

though, e.g
>
> string myClass = 'layout1'
>
> Table myTable = new myClass
>
> I know the above wont work but I hope this explains what I'm trying to do.

I'm effectively trying to decide the class to use at runtime?.
>
> Thanks
> Kieran



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What should I name my business classes given that LINQ data classes takes all table names? Ronald S. Cook Microsoft C# .NET 2 24th Jun 2008 02:57 AM
Dynamic creation of new managed classes Smugsboy Microsoft Dot NET Framework 2 25th Jan 2005 06:21 PM
Truely Dynamic Classes? =?Utf-8?B?R2FyeSBL?= Microsoft Dot NET Framework 1 30th Dec 2004 12:18 PM
Adding dynamic properties to new classes =?Utf-8?B?UmljaGFyZCBBYnJhaGFt?= Microsoft C# .NET 4 4th May 2004 01:16 PM
Dynamic Contorls & Classes MikeY Microsoft C# .NET 2 9th Jul 2003 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 PM.