tiwengr
asked on
GetControlPropertyValue code won't compile
I am struggling through a BackgroundWorker problem which is new to me and have been seeking help to get it working properly. I have received some expert comments but one of the methods suggested will not compile. Since that question is not getting any replies now, I am trying to break the problem into smaller pieces so that someone will help with the smaller part of the problem.
Here's the code:
delegate object GetControlValueCallback(Co ntrol ctrl, string propertyName);
private object GetControlPropertyValue(Co ntrol ctrl, string propertyName)
{
if (ctrl.InvokeRequired)
{
GetControlValueCallback d = new GetControlValueCallback(Ge tControlPr opertyValu e);
return ctrl.Invoke(d, new object[] { ctrl, propertyName});
}
else
{
Type t = ctrl.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (PropertyInfo p in props)
{
if (p.Name.ToUpper() == propertyName.ToUpper())
{
return p.GetValue(ctrl, propertyValue);
}
}
}
}
Unfortunately I get the following error when trying to compile:
Error 3 The name 'propertyValue' does not exist in the current context
Any suggestions would be greatly appreciated!
Here's the code:
delegate object GetControlValueCallback(Co
private object GetControlPropertyValue(Co
{
if (ctrl.InvokeRequired)
{
GetControlValueCallback d = new GetControlValueCallback(Ge
return ctrl.Invoke(d, new object[] { ctrl, propertyName});
}
else
{
Type t = ctrl.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (PropertyInfo p in props)
{
if (p.Name.ToUpper() == propertyName.ToUpper())
{
return p.GetValue(ctrl, propertyValue);
}
}
}
}
Unfortunately I get the following error when trying to compile:
Error 3 The name 'propertyValue' does not exist in the current context
Any suggestions would be greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER