Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting a string to an object property
Message
From
12/06/2008 21:32:52
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01323589
Message ID:
01323682
Views:
15
Friggin's .Net weirdness.

Thanks, Paul. I suspected the solution had something to do with reflection .... I'll try this tomorrow. Appreciate it.


>>OK, for some reason this is tough for me.
>>
>
>It's tough because it's completely non-obvious <g>.
>
>Sinec you're working with an ASP.NET app. I assumed your control references were fields, not properties.
>
>Here's what that might look like in C#
>
>string myProps = "FormView1.PageIndex";
>string[] info = myProps.Split('.');
>
>Type formType = this.GetType();
>System.Reflection.FieldInfo formInfo = formType.GetField(info[0], System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
>object control = formInfo.GetValue(this);
>
>Type propertyType = control.GetType();
>System.Reflection.PropertyInfo controlInfo = propertyType.GetProperty(info[1]);
>object propertyValue = controlInfo.GetValue(control, null);
>
>
>
>
>This (might) be the VB.NET version - I ran it through a translator so it might be a bit weird. For instance, I think the info(0) and info(1) should probably be info(1) and info(2).
>
>
>Dim myProps As String = "FormView1.PageIndex"
>Dim info As String() = myProps.Split(Microsoft.VisualBasic.ChrW(46))
>Dim formType As Type = Me.GetType()
>Dim formInfo As System.Reflection.FieldInfo = formType.GetField(info(0), System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
>Dim control As object = formInfo.GetValue(Me)
>Dim propertyType As Type = control.GetType()
>Dim controlInfo As System.Reflection.PropertyInfo = propertyType.GetProperty(info(1))
>Dim propertyValue As object = controlInfo.GetValue(control, Nothing)
>
------------------------------------------------
John Koziol, ex-MVP, ex-MS, ex-FoxTeam. Just call me "X"
"When the going gets weird, the weird turn pro" - Hunter Thompson (Gonzo) RIP 2/19/05
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform