hex type values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?amlt?=

    hex type values

    If I assign an attribute using property name/value pairs such as
    [MyAttr(stringVa l="joe")]
    where stringVal is a string C# generates the name\value pair using hex values
    01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
    I've determined 54 is a delimiter between properties and the next value OE
    represents the string type. Is there a complete table of hex values and their
    map to all the types or a particular System.Type method I could use to get
    this value?
    Any documentation on this hex representation would also be helpful.

    thanks - Jim


  • Jon Skeet [C# MVP]

    #2
    Re: hex type values

    jim <jim@discussion s.microsoft.com wrote:
    If I assign an attribute using property name/value pairs such as
    [MyAttr(stringVa l="joe")]
    where stringVal is a string C# generates the name\value pair using hex values
    01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
    I've determined 54 is a delimiter between properties and the next value OE
    represents the string type. Is there a complete table of hex values and their
    map to all the types or a particular System.Type method I could use to get
    this value?
    Any documentation on this hex representation would also be helpful.
    It's not clear to me what exactly is genering the string. You say it's
    C#, but the C# compiler isn't going to be doing this for your own
    custom attribute value.

    Could you post a short but complete program which demonstrates the
    problem?

    See http://www.pobox.com/~skeet/csharp/complete.html for details of
    what I mean by that.

    --
    Jon Skeet - <skeet@pobox.co m>
    Web site: http://www.pobox.com/~skeet
    Blog: http://www.msmvps.com/jon.skeet
    C# in Depth: http://csharpindepth.com

    Comment

    • =?Utf-8?B?amlt?=

      #3
      Re: hex type values

      when running ILDASM on the following program created by C# you can see
      the attribute values on the program class:

      using System;
      using System.Reflecti on;

      namespace ConsoleApplicat ion8
      {
      class MyAttribute : Attribute
      {
      private string sval;
      public string stringVal
      {
      get { return sval; }
      set { sval = value; }
      }
      }
      [My(stringVal="j oe")]
      class Program
      {
      static void Main(string[] args)
      {
      }
      }
      }


      "Jon Skeet [C# MVP]" wrote:
      jim <jim@discussion s.microsoft.com wrote:
      If I assign an attribute using property name/value pairs such as
      [MyAttr(stringVa l="joe")]
      where stringVal is a string C# generates the name\value pair using hex values
      01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
      I've determined 54 is a delimiter between properties and the next value OE
      represents the string type. Is there a complete table of hex values and their
      map to all the types or a particular System.Type method I could use to get
      this value?
      Any documentation on this hex representation would also be helpful.
      >
      It's not clear to me what exactly is genering the string. You say it's
      C#, but the C# compiler isn't going to be doing this for your own
      custom attribute value.
      >
      Could you post a short but complete program which demonstrates the
      problem?
      >
      See http://www.pobox.com/~skeet/csharp/complete.html for details of
      what I mean by that.
      >
      --
      Jon Skeet - <skeet@pobox.co m>
      Web site: http://www.pobox.com/~skeet
      Blog: http://www.msmvps.com/jon.skeet
      C# in Depth: http://csharpindepth.com
      >

      Comment

      • christery@gmail.com

        #4
        Re: hex type values

        [MyAttr(stringVa l="joe")]

        Dont know, but might it be unicode? This looks like a explanation...

        In the current implementation at least, strings take up 20+(n/2)*4
        bytes (rounding the value of n/2 down), where n is the number of
        characters in the string. The string type is unusual in that the size
        of the object itself varies.

        Found at http://www.yoda.arachsys.com/csharp/strings.html

        //CY

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: hex type values

          jim <jim@discussion s.microsoft.com wrote:
          when running ILDASM on the following program created by C# you can see
          the attribute values on the program class:
          Well, you can see the IL representation - but why is that important to
          you? Surely the important point is getting the attribute value in code,
          which you do with reflection, where the IL representation doesn't
          matter at all.

          The IL representation will be documented in ECMA 335, but very few
          situations will really need to know about it.

          --
          Jon Skeet - <skeet@pobox.co m>
          Web site: http://www.pobox.com/~skeet
          Blog: http://www.msmvps.com/jon.skeet
          C# in Depth: http://csharpindepth.com

          Comment

          • Rick Lones

            #6
            Re: hex type values

            jim wrote:
            If I assign an attribute using property name/value pairs such as
            [MyAttr(stringVa l="joe")]
            where stringVal is a string C# generates the name\value pair using hex values
            01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
            I've determined 54 is a delimiter between properties and the next value OE
            represents the string type. Is there a complete table of hex values and their
            map to all the types or a particular System.Type method I could use to get
            this value?
            Any documentation on this hex representation would also be helpful.
            >
            thanks - Jim
            >
            >
            Well, FWIW it's obvious enough that '09 73 74 72 69 6E 67 56 61 6C' is the
            length of "stringVal" followed by the string itself (in 8-bit ASCII) and '03 6A
            6F 65' is the length of "joe" followed by the string itself. But why in the
            world do you care?

            HTH,
            -rick-

            Comment

            Working...