M
michelQA
I have to classes :
public Class ClassA
{
//Some properties definitions common to all my classes
}
[TypeConverter(typeof(TestConverter))]
public class MyButton: System.Windows.Forms.Button
{
//....
}
and a type converter to filter properties :
class TestConverter : ExpandableObjectConverter
{
public override PropertyDescriptorCollection GetProperties
(ITypeDescriptorContext context, object value, System.Attribute[]
attributes)
{
PropertyDescriptorCollection orig = base.GetProperties(context,
value, attributes);
List<PropertyDescriptor> list = new List<PropertyDescriptor>
(orig.Count);
foreach (PropertyDescriptor pd in orig)
{
PropertyDescriptor prop;
if (pd.Name != "SomeUnwantedProp")
list.Add(pd);
}
return new PropertyDescriptorCollection(list.ToArray());
}
}
1- Is there a way to combine ClassA with MyButton class? I have a lot
of classes like ListView,TextBox etc... and I want to add the same
"custom" properties in all classes...I dont want to paste the code on
each in all classes is there a way to do that?
2- Is it possible to add custom properties in the type converter?
Since I can filter and remove properties in the Converter I suppose we
can also add item somehow?
3- What is the best way to add my customs properties to many classes?
4- Is it a good idea to define all my "form" classes like this in my
project? Maybe I'm looking for a solution where a single smart
function can parse all classes (like button,checkbox,etc..) and add my
additionnal properties. This object is to be shown in a
propertyGrid....is this make sense?
Thanks
public Class ClassA
{
//Some properties definitions common to all my classes
}
[TypeConverter(typeof(TestConverter))]
public class MyButton: System.Windows.Forms.Button
{
//....
}
and a type converter to filter properties :
class TestConverter : ExpandableObjectConverter
{
public override PropertyDescriptorCollection GetProperties
(ITypeDescriptorContext context, object value, System.Attribute[]
attributes)
{
PropertyDescriptorCollection orig = base.GetProperties(context,
value, attributes);
List<PropertyDescriptor> list = new List<PropertyDescriptor>
(orig.Count);
foreach (PropertyDescriptor pd in orig)
{
PropertyDescriptor prop;
if (pd.Name != "SomeUnwantedProp")
list.Add(pd);
}
return new PropertyDescriptorCollection(list.ToArray());
}
}
1- Is there a way to combine ClassA with MyButton class? I have a lot
of classes like ListView,TextBox etc... and I want to add the same
"custom" properties in all classes...I dont want to paste the code on
each in all classes is there a way to do that?
2- Is it possible to add custom properties in the type converter?
Since I can filter and remove properties in the Converter I suppose we
can also add item somehow?
3- What is the best way to add my customs properties to many classes?
4- Is it a good idea to define all my "form" classes like this in my
project? Maybe I'm looking for a solution where a single smart
function can parse all classes (like button,checkbox,etc..) and add my
additionnal properties. This object is to be shown in a
propertyGrid....is this make sense?
Thanks