hex type values

J

jim

If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="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
 
J

Jon Skeet [C# MVP]

jim said:
If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="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.
 
J

jim

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

using System;
using System.Reflection;

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


Jon Skeet said:
jim said:
If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="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 - <[email protected]>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
 
J

Jon Skeet [C# MVP]

jim said:
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.
 
C

christery

[MyAttr(stringVal="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
 
R

Rick Lones

jim said:
If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="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-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top