Reflection + Linq + type casting
I need to cast the type into the (of type) on last line
cbo.DataSource = DirectCast(GetType(RFOPSEntities) _
.GetProperty(entityName & "s") _
.GetGetMethod() _
.Invoke(m_Entities, Nothing), ObjectSet(Of ACAmp)))
开发者_如何学编程 .OrderBy(Function(c As ACAmp)) c.SortOrder).ToList()
Now I need to do semeting like that:
cbo.DataSource = DirectCast(GetType(RFOPSEntities) _
.GetProperty(entityName & "s") _
.GetGetMethod() _
.Invoke(m_Entities, Nothing), ObjectSet(Of Type.GetType("ACAmp"))).OrderBy(Function(c As Type.GetType("ACAmp")) c.SortOrder).ToList()
The Type.GetType("ACAmp") is not goog but the type could be pass by string. How ?
What you are trying to do is impossible. Generic parameters - (Of XYZ)
- need to be known at compile time, but GetType("ACAmp")
is executed at runtime.
精彩评论