PC Review


Reply
Thread Tools Rate Thread

How to code the creation of object when the class is not known?

 
 
=?Utf-8?B?UGV0ZXI=?=
Guest
Posts: n/a
 
      18th Jul 2007
Normally, to create an object instance based on a specific class, we can do
this.

Dim someObj As Object
someObj = New Class

However,I want to create an object instance based on a variable or
something. For example, I have 3 classes: Class1, Class2, Class3. The
variable dynamicClass can be equal to any of the 3 classes

Dim someObj As Object
someObj = New dynamicClass



 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      18th Jul 2007
"Peter" <(E-Mail Removed)> schrieb
> Normally, to create an object instance based on a specific class, we
> can do this.
>
> Dim someObj As Object
> someObj = New Class
>
> However,I want to create an object instance based on a variable or
> something. For example, I have 3 classes: Class1, Class2, Class3.
> The variable dynamicClass can be equal to any of the 3 classes
>
> Dim someObj As Object
> someObj = New dynamicClass



http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx

In particular:
http://msdn2.microsoft.com/en-us/library/k3a58006.aspx
(search for "CreateInstance")


Armin
 
Reply With Quote
 
=?Utf-8?B?UGV0ZXI=?=
Guest
Posts: n/a
 
      19th Jul 2007
Thanks Armin. I hope I can understand it (reflection) since I'm new to
..net. I hope MS has a webcast to explain it.

"Armin Zingler" wrote:

> "Peter" <(E-Mail Removed)> schrieb
> > Normally, to create an object instance based on a specific class, we
> > can do this.
> >
> > Dim someObj As Object
> > someObj = New Class
> >
> > However,I want to create an object instance based on a variable or
> > something. For example, I have 3 classes: Class1, Class2, Class3.
> > The variable dynamicClass can be equal to any of the 3 classes
> >
> > Dim someObj As Object
> > someObj = New dynamicClass

>
>
> http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx
>
> In particular:
> http://msdn2.microsoft.com/en-us/library/k3a58006.aspx
> (search for "CreateInstance")
>
>
> Armin
>

 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      19th Jul 2007
"Peter" <(E-Mail Removed)> schrieb
> Thanks Armin. I hope I can understand it (reflection) since I'm
> new to .net. I hope MS has a webcast to explain it.


Do you really need it? I mean, a class name in a variable. What are you
trying to accomplish?


Armin

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXI=?=
Guest
Posts: n/a
 
      19th Jul 2007
Hi Armin,

One example is that I have 2 windows forms with the same name but in
different path. I want to create an instance of the form but the class may
be one of 2 forms depending on some conditions.




"Armin Zingler" wrote:

> "Peter" <(E-Mail Removed)> schrieb
> > Thanks Armin. I hope I can understand it (reflection) since I'm
> > new to .net. I hope MS has a webcast to explain it.

>
> Do you really need it? I mean, a class name in a variable. What are you
> trying to accomplish?
>
>
> Armin
>
>

 
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
Reusable n-tier data class object creation, supporting Microsoft Visual Studio 2008 and LINQ fiona@crainiate.net Microsoft Dot NET 0 5th Jun 2007 09:38 AM
referencing Global Object in code behind class sonny.stevenson@gmail.com Microsoft ASP .NET 0 17th Apr 2007 04:27 AM
Object creation of class having constant. archana Microsoft C# .NET 3 9th Jan 2007 02:28 PM
prevent creation of object for a class tony Microsoft C# .NET 4 26th Aug 2006 02:53 AM
Class Code for Excel, Import OLE Object Files lindyr Microsoft Access Form Coding 4 13th Aug 2004 03:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 PM.