Ok, so Activator isn't working th eway I want to (I could be doing something
wrong)
Here is my current code
Public Function CreateEosBase(ByVal sType As String) As EOSBaseComponent
Dim tType As System.Type
Dim _EOSBase As EOSBaseComponent
Try
tType = System.Type.GetType(sType)
_EOSBase = CType(System.Activator.CreateInstance(tType), EOSBaseComponent)
Return _EOSBase
Catch ex As Exception
Console.WriteLine("Error:" & Me.GetType.ToString() & " " & ex.Message)
End Try
End Function
And type keeps coming back NullReferenceException
Ideas?
CJ
<bu********@yahoo.com> wrote in message
news:01****************************@phx.gbl...
Well, I've done something like that in a differnt way.
I get all Assembly, Class and method on the fly and
execute it.
NOTE: to use "LoadWithPartialName" you need u'r assembly
in the GAC.
'Load the DLL
objRef =
System.Reflection.Assembly.LoadWithPartialName(str DLLName)
If objRef Is Nothing Then Throw New
Exception("Assembly : '" & strDLLName & "' could not be
loaded.")
'Instansiate the Class
objInstance = objRef.CreateInstance
(strClassName)
If objInstance Is Nothing Then Throw New
Exception("Class : '" & strClassName & "' could not be
instantiated.")
'Call the Function
CallByName(objInstance, strMethodName,
CallType.Method, Object)
-----Original Message-----
Nevermind found it.
For thsoe that want the answer, its in the Activator
class. (Systemnamespace).
I'll let you know how it goes.
-CJ
"CJ Taylor" <ct*****@mortonwelding.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl... I think I've seen this somewhere, but I cannot remember how to initialze a class by a string.
That is, I have a class(Component) that I want to
initialize on the fly.It is derived from a base component I created.
So basically I have.
Public class myDerivedComponent
inherits myBaseComponent
... stuff ...
End Class
and in another code I want to have
dIm myString as String = "myDerivedComponent"
Dim myD as myBaseComponent
myD.InstanceOf (myString)
Hopefully this makes sense.
-CJ
.