Class with different properties

  • Thread starter Thread starter Robert Bravery
  • Start date Start date
R

Robert Bravery

Hi all,

How do I aproach this.
I need to have a class that has different popeties based on a givien value
eg

if the company value >35
then myclass should have theses two properties
bigvalue
lagecompany
someproperty
else the properties should be
smalvalue
someproperty

Thanks
Robert
 
What is the reason for this? Can't you just simply selectively show
those values in the UI?

You cannot change the actual properties that the class itself has -
but you could have two classes inherited from a common base-class. Not
necessarily helpful here, though.

If this relates to serialization (xml etc) then you can provide "bool
ShouldSerialize{PropertyName}()" methods for each property, to
indicate if they should be written.

For UI / binding scenarios, it is possible to change the
PropertyDescriptor set at runtime (by implementing
ICustomTypeDescriptor, ITypedList or TypeDescriptionProvider), but
before going into much detail, I'd love to know what you are trying to
do - there are probably *far* simpler ways of doing it!

As an example, if this relates to PropertyGrid, then you could mark
the properties with two sets of attributes, and use this in the
BrowsableAttributes filter.

Marc
 
Robert Bravery said:
Hi all,

How do I aproach this.
I need to have a class that has different popeties based on a givien value
eg

if the company value >35
then myclass should have theses two properties
bigvalue
lagecompany
someproperty
else the properties should be
smalvalue
someproperty

Sounds to me that you should have these properties:-

Int32 value { get; set; }
bool large { get { return value > 35; } }
T someproperty { get; set; }
 
Hi,

Could you care to explain why you need something like this?
 
I would do it this way:

1) create a class that has data that is common
to all of your "subsets", like someproperty

2) include an enumeration called something like "data type"

3) include a property called something like "subdata" that is an object

4) create a class with just bigvalue and largecompany (datatype = 1)

5) create a class with just smallvalue (datatype = 2)

6) when you instantiate the class from step 1, set the datatype,
instantiate the subclass that you want to use, and set the property
from #3 (subdata) = that object

Robin S.
GoldMail, Inc.
 

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

Back
Top