Type.GetProperties() question

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

    Type.GetProperties() question

    Hello All,
    Does anyone know what order GetProperties() returns public properties in?
    I'm using custom Attributes on the properties of my Business objects
    (NHibernate) to let me know if they should be displayed in a grid or not. I
    would like them to display in the order in which I've defined them in the
    class, but GetProperties() seems to return the properties "out of whack"
    from how I've coded them. Is there any kind of ordinal property or something
    to that effect?
    Any help is greatly appreciated
    Sincerely,
    Patrick


  • Tom Shelton

    #2
    Re: Type.GetPropert ies() question


    Patrick wrote:
    Hello All,
    Does anyone know what order GetProperties() returns public properties in?
    I'm using custom Attributes on the properties of my Business objects
    (NHibernate) to let me know if they should be displayed in a grid or not. I
    would like them to display in the order in which I've defined them in the
    class, but GetProperties() seems to return the properties "out of whack"
    from how I've coded them. Is there any kind of ordinal property or something
    to that effect?
    Any help is greatly appreciated
    Sincerely,
    Patrick
    Patrick,

    ..NET does not keep these things in any particular order. The only way
    to do this is to add a parameter to your attribute that tells it's
    order.

    --
    Tom Shelton

    Comment

    • Patrick

      #3
      Re: Type.GetPropert ies() question

      Ok, I'm dumb...it was as problem when loading into the grid, not with
      reflection. Appearently GetProperties does return them in the order in wich
      they were coded.

      "Patrick" <cparker@home.c omwrote in message
      news:uFBlKLX%23 GHA.4428@TK2MSF TNGP04.phx.gbl. ..
      Hello All,
      Does anyone know what order GetProperties() returns public properties in?
      I'm using custom Attributes on the properties of my Business objects
      (NHibernate) to let me know if they should be displayed in a grid or not.
      I would like them to display in the order in which I've defined them in
      the class, but GetProperties() seems to return the properties "out of
      whack" from how I've coded them. Is there any kind of ordinal property or
      something to that effect?
      Any help is greatly appreciated
      Sincerely,
      Patrick
      >

      Comment

      • Patrick

        #4
        Re: Type.GetPropert ies() question

        Thanks Tom for the quick reply. (I love the professionals :) I can
        certainly do that, although I'd hate to have to maintain hardcoded indexes
        when properties are added or deleted! But since I don't have a choice....
        (Listen up MS programmers! I want reflected properties to come back in the
        order they were coded! heh heh)
        Best wishes,
        Patrick

        "Tom Shelton" <tom_shelton@co mcast.netwrote in message
        news:1161918771 .030541.224320@ i3g2000cwc.goog legroups.com...
        >
        Patrick wrote:
        >Hello All,
        > Does anyone know what order GetProperties() returns public properties
        >in?
        >I'm using custom Attributes on the properties of my Business objects
        >(NHibernate) to let me know if they should be displayed in a grid or not.
        >I
        >would like them to display in the order in which I've defined them in the
        >class, but GetProperties() seems to return the properties "out of whack"
        >from how I've coded them. Is there any kind of ordinal property or
        >something
        >to that effect?
        >Any help is greatly appreciated
        >Sincerely,
        >Patrick
        >
        Patrick,
        >
        .NET does not keep these things in any particular order. The only way
        to do this is to add a parameter to your attribute that tells it's
        order.
        >
        --
        Tom Shelton
        >

        Comment

        • Tom Shelton

          #5
          Re: Type.GetPropert ies() question


          Patrick wrote:
          Ok, I'm dumb...it was as problem when loading into the grid, not with
          reflection. Appearently GetProperties does return them in the order in wich
          they were coded.
          >
          "Patrick" <cparker@home.c omwrote in message
          news:uFBlKLX%23 GHA.4428@TK2MSF TNGP04.phx.gbl. ..
          Hello All,
          Does anyone know what order GetProperties() returns public properties in?
          I'm using custom Attributes on the properties of my Business objects
          (NHibernate) to let me know if they should be displayed in a grid or not.
          I would like them to display in the order in which I've defined them in
          the class, but GetProperties() seems to return the properties "out of
          whack" from how I've coded them. Is there any kind of ordinal property or
          something to that effect?
          Any help is greatly appreciated
          Sincerely,
          Patrick
          Patrick - I maybe the one who is dumb here :) But, I'm pretty sure I
          have a case where GetProperties indeed does not return the properties
          in the order of declaration. Thinking about this, it would be the
          natural assumption that it would return the properties in vtable order,
          and that the vtable would be in the order of declaration - but, I'm not
          100% sure that is really the case or is guaranteed. I am going to look
          at that code tomorrow, and maybe do a little more research here.

          --
          Tom Shelton

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: Type.GetPropert ies() question

            Patrick <cparker@home.c omwrote:
            Thanks Tom for the quick reply. (I love the professionals :) I can
            certainly do that, although I'd hate to have to maintain hardcoded indexes
            when properties are added or deleted! But since I don't have a choice....
            (Listen up MS programmers! I want reflected properties to come back in the
            order they were coded! heh heh)
            With partial classes, the very concept of "the order they were coded"
            doesn't even exist any more...

            --
            Jon Skeet - <skeet@pobox.co m>
            http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
            If replying to the group, please do not mail me too

            Comment

            • Adam Clauss

              #7
              Re: Type.GetPropert ies() question

              "Tom Shelton" <tom_shelton@co mcast.netwrote in message
              news:1161935648 .937410.82770@k 70g2000cwa.goog legroups.com...
              Patrick - I maybe the one who is dumb here :) But, I'm pretty sure I
              have a case where GetProperties indeed does not return the properties
              in the order of declaration. Thinking about this, it would be the
              natural assumption that it would return the properties in vtable order,
              and that the vtable would be in the order of declaration - but, I'm not
              100% sure that is really the case or is guaranteed. I am going to look
              at that code tomorrow, and maybe do a little more research here.
              I suspect it's much like running a SELECT query on a database without
              specifying an 'ORDER BY' clause and hoping to get rows back in the same
              order they were added. It *might* happen by chance - but technically
              speaking the order is undefined.

              --
              Adam Clauss


              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: Type.GetPropert ies() question

                Adam Clauss <cabadam@tamu.e duwrote:
                "Tom Shelton" <tom_shelton@co mcast.netwrote in message
                news:1161935648 .937410.82770@k 70g2000cwa.goog legroups.com...
                Patrick - I maybe the one who is dumb here :) But, I'm pretty sure I
                have a case where GetProperties indeed does not return the properties
                in the order of declaration. Thinking about this, it would be the
                natural assumption that it would return the properties in vtable order,
                and that the vtable would be in the order of declaration - but, I'm not
                100% sure that is really the case or is guaranteed. I am going to look
                at that code tomorrow, and maybe do a little more research here.
                >
                I suspect it's much like running a SELECT query on a database without
                specifying an 'ORDER BY' clause and hoping to get rows back in the same
                order they were added. It *might* happen by chance - but technically
                speaking the order is undefined.
                Or at least, it's undefined *in general*, although some databases may
                well define an order.

                --
                Jon Skeet - <skeet@pobox.co m>
                http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                If replying to the group, please do not mail me too

                Comment

                • Tom Shelton

                  #9
                  Re: Type.GetPropert ies() question


                  Jon wrote:
                  Patrick <cparker@home.c omwrote:
                  Thanks Tom for the quick reply. (I love the professionals :) I can
                  certainly do that, although I'd hate to have to maintain hardcoded indexes
                  when properties are added or deleted! But since I don't have a choice....
                  (Listen up MS programmers! I want reflected properties to come back in the
                  order they were coded! heh heh)
                  >
                  With partial classes, the very concept of "the order they were coded"
                  doesn't even exist any more...

                  Good point. I don't think there has ever been a guarentee on this
                  anyway.

                  --
                  Tom Shelton

                  Comment

                  • Adam Clauss

                    #10
                    Re: Type.GetPropert ies() question

                    "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
                    news:MPG.1fac87 18160997d298d59 e@msnews.micros oft.com...
                    Adam Clauss <cabadam@tamu.e duwrote:
                    >I suspect it's much like running a SELECT query on a database without
                    >specifying an 'ORDER BY' clause and hoping to get rows back in the same
                    >order they were added. It *might* happen by chance - but technically
                    >speaking the order is undefined.
                    >
                    Or at least, it's undefined *in general*, although some databases may
                    well define an order.
                    Very true

                    --
                    Adam Clauss


                    Comment

                    Working...