Gazarsgo,
In addition to the other comments.
| Is there some parallel to the Generics concept that extends to
| having strictly-typed classes at run-time?
That is the major point behind Generics. You have strictly-typed classes at
compile & runtime
For example:
' create a loosely typed collection of integers in .NET 1.x
Dim aList As New ArrayList
aList.Add(1)
aList.Add(2)
aList.Add("Silly Me") ' allowed as its loosely typed!
' create a strictly-typed collection of integers in .NET 2.0
Dim aList As New List(Of Integer)
aList.Add(1)
aList.Add(2)
aList.Add("Silly Me") ' Compile error as its strictly typed!
| This seems to be a bit of a contradiction, but how can I construct a
| Generic class using a System.Type variable that is assigned at run
| time?
You should be able to use Type.MakeGenericType & Activator.CreateInstance,
something like:
Dim aType As Type = GetType(String)
Dim theCollectionType As Type =
GetType(System.Collections.ObjectModel.Collection( Of ))
Dim myColType As Type = theCollectionType.MakeGenericType(aType)
Dim mycol As Object = Activator.CreateInstance(myColType)
HOWEVER: Without knowing the actual type at compile time, you will only be
able to use late binding, Reflection, & object variables with the created
type, plus
possibly a handful of interfaces.
| I would gladly give up the compile-time errors if I could get rid of
| all these CType()s :)
?? CType doesn't help with have a variable of System.Type per se. However
Generics should reduce or elimate the "need" for CType.
FWIW: This is a good FAQ on Generics:
http://msdn.microsoft.com/vstudio/de...ndamentals.asp
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Gazarsgo" <ga******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| This seems to be a bit of a contradiction, but how can I construct a
| Generic class using a System.Type variable that is assigned at run
| time? Is there some parallel to the Generics concept that extends to
| having strictly-typed classes at run-time?
|
| I would gladly give up the compile-time errors if I could get rid of
| all these CType()s :)
|