keezebees
asked on
Loading a class from a string with a class name.
I don't no if this is easy to do?
I would like to make a function like
FillCombo(ddControl, CollectionClass, ValueField, TextField, NeedsNullValueRow)
this is the code that works:
Dim BuyerCol As New Csb.EabOrder.EabOrderBuyer Collection
BuyerCol.LoadAll()
Dim buyer As Csb.EabOrder.EabOrderBuyer
dropdown.Items.Clear()
Dim FirstlistItem As New ListItem("", "")
dropdown.Items.Add(Firstli stItem)
For Each Buyer In BuyerCol
Dim listItem As New ListItem(Buyer.BuyerName, Buyer.BuyerId)
dropdown.Items.Add(listIte m)
Next
Thanks.
I would like to make a function like
FillCombo(ddControl, CollectionClass, ValueField, TextField, NeedsNullValueRow)
this is the code that works:
Dim BuyerCol As New Csb.EabOrder.EabOrderBuyer
BuyerCol.LoadAll()
Dim buyer As Csb.EabOrder.EabOrderBuyer
dropdown.Items.Clear()
Dim FirstlistItem As New ListItem("", "")
dropdown.Items.Add(Firstli
For Each Buyer In BuyerCol
Dim listItem As New ListItem(Buyer.BuyerName, Buyer.BuyerId)
dropdown.Items.Add(listIte
Next
Thanks.
I don't get what you want ?
ASKER
Sorry, should be al little more specific.
What i want is an function that automates the listed code
To do that I would have to be able to make an instance of the some classes just by there class name (string)
And thats what my problem is.
How do ik load the class 'Csb.EabOrder.EabOrderBuye r' as an instance based on only a class name??
public Function FillCombo(ddControl as dropdownlist, CollectionClassName as string, ValueField as string, TextField as string, NeedsNullValueRow as boolean) as boolean
Hope this is more clear.
What i want is an function that automates the listed code
To do that I would have to be able to make an instance of the some classes just by there class name (string)
And thats what my problem is.
How do ik load the class 'Csb.EabOrder.EabOrderBuye
public Function FillCombo(ddControl as dropdownlist, CollectionClassName as string, ValueField as string, TextField as string, NeedsNullValueRow as boolean) as boolean
Hope this is more clear.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks mohzedan.
Any Idea why i get an 'object reference not set to an instance of an object' error??
NullReference exception was unhandled by user code
Private Sub test()
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly .GetExecut ingAssembl y
Dim instance As Object = asm.CreateInstance("csb.Ea bOrder.Eab OrderVerko opOrderVie wCollectio n")
'object reference error is here!!!!!
Dim Enumer As IEnumerator = CType(instance, IEnumerable).GetEnumerator
While Enumer.movenext
Dim buyer As Object = Enumer.Current
'Work with the buyer object
End While
End Sub
Any Idea why i get an 'object reference not set to an instance of an object' error??
NullReference exception was unhandled by user code
Private Sub test()
Dim asm As System.Reflection.Assembly
Dim instance As Object = asm.CreateInstance("csb.Ea
'object reference error is here!!!!!
Dim Enumer As IEnumerator = CType(instance, IEnumerable).GetEnumerator
While Enumer.movenext
Dim buyer As Object = Enumer.Current
'Work with the buyer object
End While
End Sub
try using eaborderverkooporderviewCo llection
only in the createinstance...
and could you run this code
after dim asm .....
Dim types As Type() = asm.GetTypes
for i as integer = 0 to asm.length-1
Console.writeline(asm(i).N ame)
next
and the names of the types that are printed are the names you could load using this way.
i.e. asm.createinstance("name of type from the list printed")
only in the createinstance...
and could you run this code
after dim asm .....
Dim types As Type() = asm.GetTypes
for i as integer = 0 to asm.length-1
Console.writeline(asm(i).N
next
and the names of the types that are printed are the names you could load using this way.
i.e. asm.createinstance("name of type from the list printed")
the exception is because the type name wasn't found in that assembly ... if it is contained in a dll then that dll should be loaded ... if that type is in your namespace just check it's type name correctly ...
ASKER
ehh...
asm.length doesnt excists....
Must be getting to late for me:)
asm.length doesnt excists....
Must be getting to late for me:)
sorry i meant types.length must be too late for me too . :)
ASKER
Like this right?
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly .GetExecut ingAssembl y
Dim instance As Object = asm.CreateInstance("Csb.Ea bOrder.Eab OrderVerko opOrder")
Dim types As Type() = asm.GetTypes
For i As Integer = 0 To types.Length - 1
MsgBox(types(i).Name)
Next
Dim asm As System.Reflection.Assembly
Dim instance As Object = asm.CreateInstance("Csb.Ea
Dim types As Type() = asm.GetTypes
For i As Integer = 0 To types.Length - 1
MsgBox(types(i).Name)
Next
yes but instead of the msgbox use console.writeline(types(i) .name)
that way you'll have them written in the output window
that way you'll have them written in the output window
ASKER
Here is the output:
MyComputer
MyProject
ThreadSafeObjectProvider`1
desktopmodules_csb_eaborde r_editcsb_ eaborder_a scx
EditCsb_EabOrder
desktopmodules_csb_eaborde r_viewcsb_ eaborder_a scx
ViewCsb_EabOrder
desktopmodules_csb_eaborde r_settings _ascx
Settings
FastObjectFactory_app_web_ yu75jgso
MyComputer
MyProject
ThreadSafeObjectProvider`1
desktopmodules_csb_eaborde r_editcsb_ eaborder_a scx
EditCsb_EabOrder
desktopmodules_csb_eaborde r_viewcsb_ eaborder_a scx
ViewCsb_EabOrder
desktopmodules_csb_eaborde r_settings _ascx
Settings
FastObjectFactory_app_web_ yu75jgso
MyComputer
MyProject
ThreadSafeObjectProvider`1
desktopmodules_csb_eaborde
EditCsb_EabOrder
desktopmodules_csb_eaborde
ViewCsb_EabOrder
desktopmodules_csb_eaborde
Settings
FastObjectFactory_app_web_
MyComputer
MyProject
ThreadSafeObjectProvider`1
desktopmodules_csb_eaborde
EditCsb_EabOrder
desktopmodules_csb_eaborde
ViewCsb_EabOrder
desktopmodules_csb_eaborde
Settings
FastObjectFactory_app_web_
ASKER
Sorry mohzedan,
Have to go now.
Will be back for another go tomorrow.
Thanks.
Have to go now.
Will be back for another go tomorrow.
Thanks.
see you tomorrow :)
ASKER
A bit late, but here are your points.
Just got it to work
Thanks.
Just got it to work
Thanks.
Sorry for being too late :)
If you need any more info post here ok ... :)
ASKER
well,
what i did was just write my code the way i would normaly do.
Do the testing making sure that I dont need to come back no more.
And then i replaced my object declaration with:
Dim instance As Object = asm.CreateInstance(Collect ionClassNa me)
intellisence obviusly wont work, but hey, who needs intellisence.........well actuali I do but dont tell anyone Ok?
can you tell me a bit more about supporting Ienumerable in a class so i could do the enumerating?
what i did was just write my code the way i would normaly do.
Do the testing making sure that I dont need to come back no more.
And then i replaced my object declaration with:
Dim instance As Object = asm.CreateInstance(Collect
intellisence obviusly wont work, but hey, who needs intellisence.........well actuali I do but dont tell anyone Ok?
can you tell me a bit more about supporting Ienumerable in a class so i could do the enumerating?
What is your collection class like ?
ASKER
I am using EntitySpaces for my DAL
You know of that??
You know of that??
I just read about it .... your collections should already implement Ienumerable