Msil metadata for interface includes "Extends : 01000000 [TypeRef]" - what does 01000000 mean?
I noticed that interface type definition metadata looks like:
TypDefName: Interfaces.IMyInterface (02000003)
Flags : [Public] [AutoLayout] [Interface] [Abstract] [AnsiClass] (000000a1)
Extends : 01000000 [TypeRef]
whereas everything else I create e.g. class, enum, struct, has an extends entry that looks like:
Extends : 01000001 [TypeRef] System.Object
(where System.Object is replaced with some other class name if the type does not inherit directly):
So, my question is:
Is "01000000" just a magic number that signifies "interface"? If so, are there other scenarios where开发者_如何学JAVA similar happens?
UPDATE
The entry for System.Object is the same:
TypDefName: System.Object (02000002)
Flags : [Public] [AutoLayout] [Class] [Serializable] [AnsiClass] [BeforeFieldInit] (00102001)
Extends : 01000000 [TypeRef]
...actually it is the same for all interfaces:
TypDefName: Interfaces.IMyOtherInterface (02000007)
Flags : [Public] [AutoLayout] [Interface] [Abstract] [AnsiClass] (000000a1)
Extends : 01000000 [TypeRef]
InterfaceImpl #1 (09000002)
This follows what is in the document listed in Hans' answer.
So, even though I can't find the bit that actually says "interfaces and System.Object do not require a TypeDef row", that must be what is happening and so this question is done.
It is a 'metadata token', it references an item in the tables in the metadata of the assembly. The first hex pair indicates the table type, the next 3 pairs is just a sequence number for the table row. Table 0x01 is the TypeRef table, table 0x02 is the TypeDef table.
This is described well in excruciating detail in Ecma-335, the standards document for the Common Language Infrastructure.
Missed the question, adding: an interface type does not have to inherit anything. Unlike a class which always derives from System.Object. Which makes metadata token 0x01000000 likely to mean "nothing". The actual table entries are however not fixed, you'd normally have to look in the table. Ildasm does it for you.
精彩评论