Class with different properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Bravery

    #1

    Class with different properties

    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

    #2
    Re: Class with different properties

    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
    PropertyDescrip tor set at runtime (by implementing
    ICustomTypeDesc riptor, ITypedList or TypeDescription Provider), 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
    BrowsableAttrib utes filter.

    Marc


    Comment

    • Anthony Jones

      #3
      Re: Class with different properties

      "Robert Bravery" <me@u.comwrot e in message
      news:C7352677-9BB9-4C58-B4C5-AFDF459FF639@mi crosoft.com...
      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; }


      --
      Anthony Jones - MVP ASP/ASP.NET


      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: Class with different properties

        Hi,

        Could you care to explain why you need something like this?

        --
        Ignacio Machin
        The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

        Mobile & warehouse Solutions.
        "Robert Bravery" <me@u.comwrot e in message
        news:C7352677-9BB9-4C58-B4C5-AFDF459FF639@mi crosoft.com...
        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
        >

        Comment

        • RobinS

          #5
          Re: Class with different properties

          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.
          --------------------------
          "Robert Bravery" <me@u.comwrot e in message
          news:C7352677-9BB9-4C58-B4C5-AFDF459FF639@mi crosoft.com...
          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
          >

          Comment

          Working...