PC Review


Reply
Thread Tools Rate Thread

CreateInstance and New Sub

 
 
Mike
Guest
Posts: n/a
 
      28th Jul 2004
I have a DLL which I am using Assembly.Load and CreateInstance to instantiate.

Dim path As String = "myDLL"
Dim className As String = path + ".SomeClass"

Dim foo As IFoo

foo = CType(System.Reflection.Assembly.Load(path).CreateInstance(className),
IFoo)

This works, and creates an instance of myDLL.className.

However I want to be able to call an overloaded constructor, e.g.

dim foo as new myDLL.SomeClass("Bar")

How can I do this using createinstance?

 
Reply With Quote
 
 
 
 
Lebrun Thomas
Guest
Posts: n/a
 
      28th Jul 2004
Have you check the variopus constructor of CreateInstance ?

--
LEBRUN Thomas
http://morpheus.developpez.com


"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a DLL which I am using Assembly.Load and CreateInstance to

instantiate.
>
> Dim path As String = "myDLL"
> Dim className As String = path + ".SomeClass"
>
> Dim foo As IFoo
>
> foo =

CType(System.Reflection.Assembly.Load(path).CreateInstance(className),
> IFoo)
>
> This works, and creates an instance of myDLL.className.
>
> However I want to be able to call an overloaded constructor, e.g.
>
> dim foo as new myDLL.SomeClass("Bar")
>
> How can I do this using createinstance?
>



 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      29th Jul 2004
Hi Mike,

You may try to use the override createinstance to pass the arguments to the
contructor.

Assembly.CreateInstance Method (String, Boolean, BindingFlags, Binder,
Object[], CultureInfo, Object[])
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemReflectionAssemblyClassCreateInstanceTopic3.asp

e.g.
Dim fm As Form
fm =
System.Reflection.Assembly.LoadFrom("C:\Test\WindowsApplication3\bin\Debug\W
indowsApplication3.exe").CreateInstance("WindowsApplication3.Form1", True,
BindingFlags.CreateInstance, Nothing, New Object() {"Hello"}, Nothing,
Nothing)
fm.Show()

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
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
purpose of CreateInstance<T> Dan Holmes Microsoft C# .NET 8 28th Jun 2006 09:31 PM
CreateInstance Bud J via DotNetMonster.com Microsoft Dot NET Framework Forms 2 13th Jul 2005 04:53 AM
Difference Between assembly.CreateInstance and System.Activator.CreateInstance John Jenkins Microsoft C# .NET 1 14th Oct 2004 10:00 PM
Difference Between CurrentDomain.CreateInstance and Activator.CreateInstance b0yce Microsoft Dot NET 0 23rd Mar 2004 03:56 PM
Difference Between CurrentDomain.CreateInstance and Activator.CreateInstance b0yce Microsoft C# .NET 0 22nd Mar 2004 04:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 AM.