smart way to add/remove properties to classes

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
 
M

michelQA

nobody?... I just need something to start with

At least is anybody know if it seems possible to add properties with
the type descriptor?

If you have to add 2-3 properties to 50 classes (inherited from
system.windows.form) How this can be done without pasting the
properties in all classes?
 
F

Family Tree Mike

michelQA said:
nobody?... I just need something to start with

At least is anybody know if it seems possible to add properties with
the type descriptor?

If you have to add 2-3 properties to 50 classes (inherited from
system.windows.form) How this can be done without pasting the
properties in all classes?

If I need to add common properties to all forms, then I would create a
class inheriting from System.Windows.Forms that adds the properties.
Then all of my forms inherit from my new forms class. Similar for other
controls.

I'm not following the TypeConverter approach you outlined first. Sorry...
 
M

michelQA

If I need to add common properties to all forms, then I would create a
class inheriting from System.Windows.Forms that adds the properties.
Then all of my forms inherit from my new forms class.  Similar for other
controls.

I'm not following the TypeConverter approach you outlined first.  Sorry....

But since a need a button, listview, checkbox, ... classes is there
any other way to add my properties instead of pasting my new props in
all inherited classes one by one?
 
M

michelQA

After many many hours....I have to go for a workaround....now I have
to change the design and I'm looking for adding a separate tab for my
extra properties in the propertyGrid...this way there is no need to
combine two classe.

I'm surprised to see how complicate it is just to add a simple stupid
string properties in a class... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top