QuoteReplyTopic: GetEntities using a System.Type variable Posted: 25-Sep-2008 at 6:20am
Is there a way to retrieve Entities using a System.Type variable instead of a generics (Of T) that cannot be set in a variable?
I would like to be able to do something like that :
Private Sub TestReflex() Dim oAms As Reflection.Assembly = Reflection.Assembly.GetCallingAssembly For Each oType As Type In oAms.GetTypes If oType.BaseType Is GetType(Entity) Then PrintAll(oType) End If Next End Sub
Private Sub PrintAll(ByVal pType As System.Type) For Each oEnt As Entity In DefaultManager.GetEntities(Of pType)() '<-- Does not compile PrintValues(Of pType.BaseType) (CType(oEnt, pType.BaseType)) '<-- Does not compile Next End Sub
Private Sub PrintValues(Of T)(ByVal pItem As T) Dim oProperties() As Reflection.PropertyInfo oProperties = GetType(T).GetProperties(Reflection.BindingFlags.DeclaredOnly _ Or Reflection.BindingFlags.Instance _ Or Reflection.BindingFlags.Public)
For Each oProp As Reflection.PropertyInfo In oProperties
If oProp.CanRead AndAlso oProp.CanWrite Then Console.WriteLine("{0} = {1}", oProp.Name, oProp.GetValue(pItem, Nothing)) ElseIf oProp.CanRead Then Console.WriteLine("{0}* = {1}", oProp.Name, oProp.GetValue(pItem, Nothing)) End If
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum