【发布时间】:2010-11-25 11:21:54
【问题描述】:
我使用此代码获取对象的子属性,
PropertyDescriptorCollection childProperties = TypeDescriptor.GetProperties(theObject)[childNode.Name].GetChildProperties();
认为“theObject”变量是一个文本框,我尝试设置 TextBox.Font.Bold = true;
我将此代码用于主要属性,并且在我自定义主要属性时它可以工作。但是当我访问子属性时,
我收到一个错误,即“对象引用未设置为对象的实例。”。
foreach (PropertyDescriptor childProperty in childProperties)
{
foreach (XmlAttribute attribute in attributes)
{
if (childProperty.Name == attribute.Name)
{
if (!childProperty.IsReadOnly)
{
object convertedPropertyValue = ConverterHelper.ConvertValueForProperty(attribute.Value, childProperty);
childProperty.SetValue(theObject, convertedPropertyValue); //exception throw here
break;
}
}
}
}
【问题讨论】:
-
你能粘贴完整的例外吗
标签: .net components