This is a migrated thread and some comments may be shown as answers.

Dynamic Select

1 Answer 77 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Frank Schürer
Top achievements
Rank 1
Frank Schürer asked on 10 Aug 2010, 02:00 PM
Hi,

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"

Dim
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?

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 11 Aug 2010, 02:48 PM
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)
 
    Console.WriteLine(name)
Next

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
Tags
LINQ (LINQ specific questions)
Asked by
Frank Schürer
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or