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
Marc Gravell - 11 Jan 2008 12:11 GMT
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
Anthony Jones - 11 Jan 2008 12:12 GMT
> Hi all,
>
[quoted text clipped - 10 lines]
> 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; }

Signature
Anthony Jones - MVP ASP/ASP.NET
Ignacio Machin ( .NET/ C# MVP ) - 11 Jan 2008 14:19 GMT
Hi,
Could you care to explain why you need something like this?

Signature
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
> Hi all,
>
[quoted text clipped - 13 lines]
> Thanks
> Robert
RobinS - 12 Jan 2008 06:35 GMT
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.
--------------------------
> Hi all,
>
[quoted text clipped - 13 lines]
> Thanks
> Robert