开发者

Reflection + Linq + type casting

开发者 https://www.devze.com 2023-03-05 17:00 出处:网络
I need to cast the type into the (of type) on last line cbo.DataSource = DirectCast(GetType(RFOPSEntities) _

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

精彩评论

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