diff options
author | jfrijters <jfrijters> | 2011-03-14 08:03:30 +0300 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-03-14 08:03:30 +0300 |
commit | 4300d8f5eaaedaf8edd363322706e428a1897363 (patch) | |
tree | 679fc97b9b2ab3f6c120abdd2b557d14b2db7d33 /reflect/Reader | |
parent | 2af3abfc91e7de453b6b8d826530b44094727376 (diff) |
- Removed TypeBuilder.__SetStructLayoutAttribute().
- Added TypeBuilder.__SetLayout().
- Added Type.__GetLayout().
- Fixed Type.StructLayoutAttribute to be compatible with .NET.
Diffstat (limited to 'reflect/Reader')
-rw-r--r-- | reflect/Reader/TypeDefImpl.cs | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/reflect/Reader/TypeDefImpl.cs b/reflect/Reader/TypeDefImpl.cs index 1a2f0171..3eea3509 100644 --- a/reflect/Reader/TypeDefImpl.cs +++ b/reflect/Reader/TypeDefImpl.cs @@ -379,7 +379,8 @@ namespace IKVM.Reflection.Reader switch (this.Attributes & TypeAttributes.LayoutMask) { case TypeAttributes.AutoLayout: - return null; + layout = new StructLayoutAttribute(LayoutKind.Auto); + break; case TypeAttributes.SequentialLayout: layout = new StructLayoutAttribute(LayoutKind.Sequential); break; @@ -389,34 +390,46 @@ namespace IKVM.Reflection.Reader default: throw new BadImageFormatException(); } - int token = this.MetadataToken; - // TODO use binary search? - for (int i = 0; i < module.ClassLayout.records.Length; i++) + switch (this.Attributes & TypeAttributes.StringFormatMask) { - if (module.ClassLayout.records[i].Parent == token) - { - layout.Pack = module.ClassLayout.records[i].PackingSize; - layout.Size = module.ClassLayout.records[i].ClassSize; - switch (this.Attributes & TypeAttributes.StringFormatMask) - { - case TypeAttributes.AnsiClass: - layout.CharSet = CharSet.Ansi; - break; - case TypeAttributes.UnicodeClass: - layout.CharSet = CharSet.Unicode; - break; - case TypeAttributes.AutoClass: - layout.CharSet = CharSet.Auto; - break; - default: - layout.CharSet = CharSet.None; - break; - } - return layout; - } + case TypeAttributes.AnsiClass: + layout.CharSet = CharSet.Ansi; + break; + case TypeAttributes.UnicodeClass: + layout.CharSet = CharSet.Unicode; + break; + case TypeAttributes.AutoClass: + layout.CharSet = CharSet.Auto; + break; + default: + layout.CharSet = CharSet.None; + break; + } + if (!__GetLayout(out layout.Pack, out layout.Size)) + { + // compatibility with System.Reflection + layout.Pack = 8; + } + return layout; + } + } + + public override bool __GetLayout(out int packingSize, out int typeSize) + { + int token = this.MetadataToken; + // TODO use binary search? + for (int i = 0; i < module.ClassLayout.records.Length; i++) + { + if (module.ClassLayout.records[i].Parent == token) + { + packingSize = module.ClassLayout.records[i].PackingSize; + typeSize = module.ClassLayout.records[i].ClassSize; + return true; } - return null; } + packingSize = 0; + typeSize = 0; + return false; } public override Module Module |