a
nested object within. Suppose class A is defined as
class A
{
.
.
.
//Property that exposes nested object
public B prop
{
get{return new B();}
}
}
and class B is defined as
class B
{
//Properties corresponding to B
public int x
{
get{return 1;}
}
.
.
.
}
If I were to bind a strongly typed collection of object A and try to bind
the collection, the property that exposes the nested object, does not show
the values. What would I require to do if I want to bind collection of A
where the properties of B are included as a "joined view" . I tried
implementing TypeConvertor and override GetProperties, but Iam unable to add
to the propertydescriptorcollection since it is not implemented.
I was wondering if there was any other approach to this whole problem. This
seems like a common scenario.
public class NestedPropertyConverter : TypeConverter
{
public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context,object value, Attribute[]
filter)
{
//Obtain the default property descriptors, add nested properties and return
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(value,
filter);
for(int i=0; i<props.Count; ++i)
{
PropertyDescriptor desc = props;
if(desc.PropertyType == Type.GetType("B"))
{
PropertyDescriptorCollection nestedProps =
TypeDescriptor.GetProperties(desc.PropertyType);
for(int j=0; j<nestedProps.Count; ++j)
{
PropertyDescriptor nestedDesc = nestedProps[j];
//Add to the top most PropertyDescriptor Collection
//CANNOT ADD SINCE NOT IMPLEMENTED
props.Add(nestedDesc);
}
}
return props;
}
}
Thanks in advance
Viktor