By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Using reflection to instantiate a class

P: n/a
Hello,
I have a problem where by wish to instantiate an object say NewReport
to a
specific class, all inherited from the base class MyReport, I have the
classname as a string and I don't want to use a massive Case Statement, I
wish to use Reflection as this is more efficient. This is how I would do it
in a case statement, how can I do it in reflection

Dim NewReport as MyReport

Select Case strReportName
Case = "OrderReport"
NewReport = New OrderReport 'Inherits MyReport
Case = "InvoiceReport"
NewReport = New InvoiceReport 'Inherits MyReport

The list is very long, I wish to just pass the string strReportName to
reflection and
reflection will get the correct class

Thanx in advance
Geri
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Geri,

Take a look at the System.Activator.CreateInstance(...) methods.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"ghobley" <gh*****@discussions.microsoft.com> escribió en el mensaje
news:D5**********************************@microsof t.com...
Hello,
I have a problem where by wish to instantiate an object say
NewReport
to a
specific class, all inherited from the base class MyReport, I have the
classname as a string and I don't want to use a massive Case Statement, I
wish to use Reflection as this is more efficient. This is how I would do
it
in a case statement, how can I do it in reflection

Dim NewReport as MyReport

Select Case strReportName
Case = "OrderReport"
NewReport = New OrderReport 'Inherits MyReport
Case = "InvoiceReport"
NewReport = New InvoiceReport 'Inherits MyReport

The list is very long, I wish to just pass the string strReportName to
reflection and
reflection will get the correct class

Thanx in advance
Geri

Nov 21 '05 #2

P: n/a
"ghobley" <gh*****@discussions.microsoft.com> schrieb:
I have a problem where by wish to instantiate an object say
NewReport
to a
specific class, all inherited from the base class MyReport, I have the
classname as a string and I don't want to use a massive Case Statement, I
wish to use Reflection as this is more efficient. This is how I would do
it
in a case statement, how can I do it in reflection


<URL:http://www.google.to/groups?selm=Or5f9nXBFHA.2180%40TK2MSFTNGP12.phx.gb l>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.