I'm an absolute newb to ASP/.Net, and this is my first task!
I'm trying to set an object property (in this example Calendar.SelectedDayStyle.BackColor) from a string value containing the property name (e.g. "SelectedDayStyle.BackColor"). From some Google searches I've managed to cobble together some code that I'd hoped would move down the object hierarchy to the target property and then set the value of that property.
Would someone be kind enough to point out what I'm doing wrong with the following:
Called like this:
The above code generates a MissingMemberException and I don't understand why!
I'd be grateful for any guidance/solutions you can provide.
Many thanks in advance.
Andy
--
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
I'm trying to set an object property (in this example Calendar.SelectedDayStyle.BackColor) from a string value containing the property name (e.g. "SelectedDayStyle.BackColor"). From some Google searches I've managed to cobble together some code that I'd hoped would move down the object hierarchy to the target property and then set the value of that property.
Would someone be kind enough to point out what I'm doing wrong with the following:
Code:
Public Sub SetPropertyFromString(ByVal TargetObject As Object, ByVal PropertyString As String, ByVal ValueToSet As String)
Dim ObjectType As Type = TargetObject.GetType()
Dim strProperty As String
Dim colTemp As Drawing.Color
For Each strProperty In PropertyString.Split(".")
Dim LocalProperty As System.Reflection.PropertyInfo
LocalProperty = ObjectType.GetProperty(strProperty)
TargetObject = LocalProperty.GetValue(TargetObject, Nothing)
ObjectType = LocalProperty.PropertyType
Next
colTemp = Drawing.Color.FromName(ValueToSet)
TargetObject.SetValue(TargetObject, colTemp, Nothing)
End Sub
Code:
SetPropertyFromString(Me.Calendar1, "SelectedDayStyle.BackColor", "Red")
I'd be grateful for any guidance/solutions you can provide.
Many thanks in advance.
Andy
--
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux