Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Class with different properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Bravery - 11 Jan 2008 11:46 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.