开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜