diff options
author | Marek Safar <marek.safar@gmail.com> | 2015-06-21 14:20:10 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2015-06-21 14:21:15 +0300 |
commit | 0780c58b982711f0bbbfa2906a7a0942ac572db9 (patch) | |
tree | 796a25baa1583cea58d2dfba63e2f4277baa5264 /mcs/class/PEAPI | |
parent | c55393e99db90d6144b03662b8cd934af86019fb (diff) |
[ilasm] Add emit of custom string attribute using member syntax
Diffstat (limited to 'mcs/class/PEAPI')
-rw-r--r-- | mcs/class/PEAPI/Metadata.cs | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/mcs/class/PEAPI/Metadata.cs b/mcs/class/PEAPI/Metadata.cs index c2351247660..c40f4a9ee95 100644 --- a/mcs/class/PEAPI/Metadata.cs +++ b/mcs/class/PEAPI/Metadata.cs @@ -444,9 +444,35 @@ namespace PEAPI { cVal = val; tabIx = MDTable.CustomAttribute; - var bac = val as ByteArrConst; + byteVal = ConstantToByteArray (val); + } + + static byte[] ConstantToByteArray (Constant c) + { + var bac = c as ByteArrConst; if (bac != null) - byteVal = bac.val; + return bac.val; + + var sc = c as StringConst; + if (sc != null) { + string value = sc.val; + if (value == null) + throw new NotImplementedException (); + + var ms = new MemoryStream (); + // Version info + ms.WriteByte (1); + ms.WriteByte (0); + + 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; + } + + throw new NotImplementedException (c.GetType ().ToString ()); } internal CustomAttribute(MetaDataElement paren, Method constrType, @@ -3169,7 +3195,7 @@ namespace PEAPI { } public class StringConst : DataConstant { - string val; + internal string val; public StringConst(string val) { |