
I have a nested property (that is, property on an object which itself is a property of another object) of type string and name "Name". Because it is so generic I can not use property type or property name to configure a custom editor for it. Furthermore, I have no access to the original object source code so I cannot annotate the property with Editor attribute.
Thus I am using CustomTypeDescriptor to wrap properties in a custom descriptor:SimplePropertyDescriptor can now return custom editor for a given property:
I used /ProductSamples/EditorsSamples/Demo/PropertyGridIntegrationCustom sample
to create my CustomNamePropertyEditor class, based on RectPropertyEditor.
All is fine and all works as expected. My editor gets shown and used for a nested property.
However, while in debugger I noticed that GetEditor() method gets called at least 5 times for a single property instance. Since I return new CustomNamePropertyEditor object each time, I am now concerned about having abandoned objects, possibly carrying some state info, hanging around. Furthermore, said property is used multiple times in the collection of objects having that property, so we are talking about possible hundreds of calls to GetEditor(), each returning a fresh editor object.
Can you shed some light on how does PropertyGrid use the value returned by GetEditor(), in consideration of it possibly being a fresh object returned after each call?
Thus I am using CustomTypeDescriptor to wrap properties in a custom descriptor:
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
var props = new PropertyDescriptorCollection(null);
foreach (PropertyInfo pi in _objectType.GetProperties())
{
props.Add(new SimplePropertyDescriptor(pi, attributes));
}
// Return the computed properties
return props;
}
public override object GetEditor(Type editorBaseType)
{
if (_prop.DeclaringType == typeof(MyInteropKey))
{
if (_prop.Name == "Name")
{
return new CustomNamePropertyEditor();
}
}
return base.GetEditor(editorBaseType);
}
to create my CustomNamePropertyEditor class, based on RectPropertyEditor.
All is fine and all works as expected. My editor gets shown and used for a nested property.
However, while in debugger I noticed that GetEditor() method gets called at least 5 times for a single property instance. Since I return new CustomNamePropertyEditor object each time, I am now concerned about having abandoned objects, possibly carrying some state info, hanging around. Furthermore, said property is used multiple times in the collection of objects having that property, so we are talking about possible hundreds of calls to GetEditor(), each returning a fresh editor object.
Can you shed some light on how does PropertyGrid use the value returned by GetEditor(), in consideration of it possibly being a fresh object returned after each call?