PublicSealed = 0x101, SpecialName = 0x400, RTSpecialName = 0x800,
Import = 0x1000, Serializable = 0x2000, UnicodeClass = 0x10000,
AutoClass = 0x20000, HasSecurity = 0x40000, BeforeFieldInit = 0x100000,
+ Forwarder = 0x200000,
VisibilityMask = 0x07 }
/// <summary>
ForwardRef = 0x10, PreserveSig = 0x0080, InternalCall = 0x1000,
Synchronised = 0x0020, Synchronized = 0x0020, NoInLining = 0x0008, Optil = 0x0002}
+ /// <summary>
+ /// Storage location for initial field data
+ /// </summary>
+ public enum DataSegment { Data, TLS, CIL }
+
/// <summary>
/// Modes for a parameter
/// </summary>
type = constrType;
cVal = val;
tabIx = MDTable.CustomAttribute;
+
+ byteVal = ConstantToByteArray (val);
+ }
+
+ static byte[] ConstantToByteArray (Constant c)
+ {
+ var bac = c as ByteArrConst;
+ if (bac != null)
+ return bac.val;
+
+ var ms = new MemoryStream ();
+ // Version info
+ ms.WriteByte (1);
+ ms.WriteByte (0);
+
+ if (c == null) {
+ ms.WriteByte (0);
+ ms.WriteByte (0);
+ return ms.ToArray ();
+ }
+
+ var sc = c as StringConst;
+ if (sc != null) {
+ string value = sc.val;
+ if (value == null)
+ throw new NotImplementedException ();
+
+ var buf = Encoding.UTF8.GetBytes (value);
+ MetaData.CompressNum ((uint) buf.Length, ms);
+ var byteVal = ms.ToArray ();
+ System.Array.Resize (ref byteVal, (int) ms.Length + buf.Length + 2);
+ System.Array.Copy (buf, 0, byteVal, ms.Length, buf.Length);
+ return byteVal;
+ }
+
+ var ac = c as ArrayConstant;
+ if (ac != null) {
+ var bw = new BinaryWriter (ms);
+ if (ac.ExplicitSize != null)
+ bw.Write (ac.ExplicitSize.Value);
+ ac.Write (bw);
+ bw.Write ((short)0);
+ return ms.ToArray ();
+ }
+
+ var bc = c as DataConstant;
+ if (bc != null) {
+ var bw = new BinaryWriter (ms);
+ bc.Write (bw);
+ bw.Write ((short)0);
+ return ms.ToArray ();
+ }
+
+ throw new NotImplementedException (c.GetType ().ToString ());
}
internal CustomAttribute(MetaDataElement paren, Method constrType,
ExternClass externClass;
internal ExternClassRef(TypeAttr attrs, string nsName, string name,
- FileRef declFile, MetaData md) : base(nsName,name,md)
+ MetaDataElement declRef, MetaData md) : base(nsName,name,md)
{
- externClass = new ExternClass(attrs,nameSpaceIx,nameIx,declFile);
+ externClass = new ExternClass(attrs,nameSpaceIx,nameIx,declRef);
metaData.AddToTable(MDTable.ExportedType,externClass);
}
/// <summary>
/// Boolean constant
/// </summary>
- public class BoolConst : Constant {
+ public class BoolConst : DataConstant {
bool val;
/// <summary>
}
public class ByteArrConst : DataConstant {
- byte[] val;
+ internal byte[] val;
public ByteArrConst(byte[] val)
{
}
- public class UIntConst : Constant {
+ public class UIntConst : DataConstant {
ulong val;
public UIntConst(byte val)
}
public class StringConst : DataConstant {
- string val;
+ internal string val;
public StringConst(string val)
{
}
}
+ public int? ExplicitSize { get; set; }
+
internal sealed override void Write(BinaryWriter bw)
{
for (int i=0; i < dataVals.Length; i++) {
Type type;
Class cmodType;
+ PrimitiveTypeRef cmodPrimType;
/// <summary>
/// Create a new custom modifier for a type
this.cmodType = cmodType;
}
+ public CustomModifiedType(Type type, CustomModifier cmod, PrimitiveTypeRef cmodType)
+ : base((byte)cmod)
+ {
+ this.type = type;
+ this.cmodPrimType = cmodType;
+ }
+
internal sealed override void TypeSig(MemoryStream str)
{
str.WriteByte(typeIndex);
- MetaData.CompressNum(cmodType.TypeDefOrRefToken(),str);
+
+ if (cmodType != null) {
+ MetaData.CompressNum(cmodType.TypeDefOrRefToken(),str);
+ } else {
+ MetaData.CompressNum(cmodPrimType.TypeDefOrRefToken(),str);
+ }
+
type.TypeSig(str);
}
}
+ public class PrimitiveTypeRef : Type
+ {
+ PrimitiveType type;
+ MetaData metaData;
+
+ internal PrimitiveTypeRef(PrimitiveType type, MetaData md)
+ : base (0)
+ {
+ this.type = type;
+ this.metaData = md;
+ }
+
+ internal uint TypeDefOrRefToken()
+ {
+ uint cIx = type.GetTypeSpec (metaData).Row;
+ cIx = (cIx << 2) | 0x2;
+ return cIx;
+ }
+ }
+
/**************************************************************************/
/// <summary>
/// Descriptor for an pointer (type * or type &)
private static readonly uint max3BitSmlIx = 0x1FFF;
private static readonly uint max5BitSmlIx = 0x7FF;
// NOTE: version and stream name strings MUST always be quad padded
-#if NET_4_0
private static readonly string version = "v4.0.30319\0\0";
-#elif NET_2_0
- private static readonly string version = "v2.0.50727\0\0";
-#else
- private static readonly string version = "v1.1.4322\0\0\0";
-#endif
private static readonly char[] tildeName = {'#','~','\0','\0'};
private static readonly char[] stringsName = {'#','S','t','r','i','n','g','s','\0','\0','\0','\0'};
private static readonly char[] usName = {'#','U','S','\0'};
MDTable tabIx = (MDTable)i;
if (count > max5BitSmlIx) {
+ if (tabIx == MDTable.Method || tabIx == MDTable.Field || tabIx == MDTable.TypeRef ||
+ tabIx == MDTable.TypeDef || tabIx == MDTable.Param || tabIx == MDTable.InterfaceImpl ||
+ tabIx == MDTable.MemberRef || tabIx == MDTable.Module || tabIx == MDTable.DeclSecurity ||
+ tabIx == MDTable.Property || tabIx == MDTable.Event || tabIx == MDTable.StandAloneSig ||
+ tabIx == MDTable.ModuleRef || tabIx == MDTable.TypeSpec || tabIx == MDTable.Assembly ||
+ tabIx == MDTable.AssemblyRef || tabIx == MDTable.File || tabIx == MDTable.ExportedType ||
+ tabIx == MDTable.ManifestResource || tabIx == MDTable.GenericParam)
lgeCIx[(int)CIx.HasCustomAttr] = true;
}
if (count > max3BitSmlIx) {
- if ((tabIx == MDTable.TypeRef) || (tabIx == MDTable.ModuleRef) || (tabIx == MDTable.Method) || (tabIx == MDTable.TypeSpec) || (tabIx == MDTable.Field))
+ if (tabIx == MDTable.Method || tabIx == MDTable.MemberRef)
lgeCIx[(int)CIx.CustomAttributeType] = true;
- if ((tabIx == MDTable.Method) || (tabIx == MDTable.MemberRef))
+ if (tabIx == MDTable.TypeDef || tabIx == MDTable.TypeRef || tabIx == MDTable.ModuleRef ||
+ tabIx == MDTable.Method || tabIx == MDTable.TypeSpec)
lgeCIx[(int)CIx.MemberRefParent] = true;
}
if (count > max2BitSmlIx) {
{
output.Seek(0,SeekOrigin.Current);
output.Write((uint)0); // Reserved
-#if NET_2_0
output.Write((byte)2); // MajorVersion
output.Write((byte)0); // MinorVersion
-#else
- output.Write((byte)1); // MajorVersion
- output.Write((byte)0); // MinorVersion
-#endif
output.Write(heapSizes);
output.Write((byte)1); // Reserved
output.Write(valid);
BuildTable(metaDataTables[(int)MDTable.TypeDef]);
BuildTable(metaDataTables[(int)MDTable.TypeSpec]);
BuildTable(metaDataTables[(int)MDTable.MemberRef]);
-#if NET_2_0
BuildTable(metaDataTables[(int)MDTable.GenericParam]);
BuildTable(metaDataTables[(int)MDTable.MethodSpec]);
BuildTable(metaDataTables[(int)MDTable.GenericParamConstraint]);
-#endif
BuildTable(metaDataTables[(int)MDTable.ManifestResource]);
if (cattr_list != null) {
SortTable(metaDataTables[(int)MDTable.DeclSecurity]);
SortTable(metaDataTables[(int)MDTable.MethodSemantics]);
SortTable(metaDataTables[(int)MDTable.ImplMap]);
-#if NET_2_0
if (metaDataTables[(int)MDTable.GenericParam] != null) {
SortTable(metaDataTables[(int)MDTable.GenericParam]);
// Now add GenericParamConstraints
}*/
}
SortTable(metaDataTables[(int)MDTable.GenericParamConstraint]);
-#endif
SortTable(metaDataTables[(int)MDTable.InterfaceImpl]);
SortTable(metaDataTables[(int)MDTable.CustomAttribute]);