Dynamic Select

2 posts, 0 answers
  1. Frank Schürer
    Frank Schürer avatar
    13 posts
    Member since:
    Aug 2009

    Posted 10 Aug 2010 Link to this post


    i am currently trying to implement a dynamic select through linq by passing a specific setting name.
    My intention is to get a value of a dynamic specified column name.

    A first try is this here...

    sSettingname = "XMLLayout"

    objScope As IObjectScope = ObjectScopeProviderMC.GetNewObjectScope()
    Dim sUsername As String = System.Environment.UserName
    Dim Settings = (From Sets In objScope.Extent(Of EnvSettings)() _
               Where Sets.User = sUsername.ToLower _
               Select ("new(" & sSettingname & " AS MyValue)"))

    But my question is how can i access MyValue?
  2. Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 11 Aug 2010 Link to this post

    Hello Frank Schürer,

    You could use reflection to access the property’s value:

    For Each item As var In Settings
        Dim t As Type = item.GetType()
        Dim name As Object = t.GetProperty("MyValue").GetValue(item, Nothing)

    Hope that helps.

    All the best,
    Damyan Bogoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top