[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mcs / class / System.Runtime.Serialization / binary-writer-method-gen.cs
1 // mono binary-writer-method-gen.exe > System.Xml/XmlBinaryDictionaryWriterAutoGen.cs
2 using System;
3 using System.Collections.Generic;
4 using System.Globalization;
5 using System.CodeDom;
6 using System.CodeDom.Compiler;
7 using Microsoft.CSharp;
8
9 public class Generator
10 {
11         public static void Main ()
12         {
13                 Console.Out.NewLine = "\n";
14                 Type [] types = new Type [] {
15                         typeof (bool), typeof (DateTime), typeof (decimal), typeof (double),
16                         typeof (Guid), typeof (short), typeof (int), typeof (long), typeof (float), typeof (TimeSpan) };
17
18                 Dictionary<Type,byte> table = new Dictionary<Type,byte> ();
19                 // LAMESPEC: [MC-NBFX] section 2.3.3 dedscribes wrong RecordTypes.
20                 table.Add (typeof (bool), 0xB5);
21                 table.Add (typeof (short), 0x8B);
22                 table.Add (typeof (int), 0x8D);
23                 table.Add (typeof (long), 0x8F);
24                 table.Add (typeof (float), 0x91);
25                 table.Add (typeof (double), 0x93);
26                 table.Add (typeof (decimal), 0x95);
27                 table.Add (typeof (DateTime), 0x97);
28                 table.Add (typeof (TimeSpan), 0xAF);
29                 table.Add (typeof (Guid), 0xB1);
30
31                 Console.WriteLine (@"
32 using System;
33 using BF = System.Xml.XmlBinaryFormat;
34
35 namespace System.Xml
36 {
37         internal partial class XmlBinaryDictionaryWriter : XmlDictionaryWriter
38         {
39                 void CheckWriteArrayArguments (Array array, int offset, int length)
40                 {
41                         if (array == null)
42                                 throw new ArgumentNullException (""array"");
43                         if (offset < 0)
44                                 throw new ArgumentOutOfRangeException (""offset is negative"");
45                         if (offset > array.Length)
46                                 throw new ArgumentOutOfRangeException (""offset exceeds the length of the destination array"");
47                         if (length < 0)
48                                 throw new ArgumentOutOfRangeException (""length is negative"");
49                         if (length > array.Length - offset)
50                                 throw new ArgumentOutOfRangeException (""length + offset exceeds the length of the destination array"");
51                 }
52
53                 void CheckDictionaryStringArgs (XmlDictionaryString localName, XmlDictionaryString namespaceUri)
54                 {
55                         if (localName == null)
56                                 throw new ArgumentNullException (""localName"");
57                         if (namespaceUri == null)
58                                 throw new ArgumentNullException (""namespaceUri"");
59                 }
60 ");
61
62                 foreach (Type type in types) {
63                         Console.WriteLine (@"
64
65                 public override void WriteArray (string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, {0} [] array, int offset, int length)
66                 {{
67                         CheckDictionaryStringArgs (localName, namespaceUri);
68                         writer.Write (BF.Array);
69                         WriteStartElement (prefix, localName, namespaceUri);
70                         WriteEndElement ();
71                         WriteArrayRemaining (array, offset, length);
72                 }}
73
74                 public override void WriteArray (string prefix, string localName, string namespaceUri, {0} [] array, int offset, int length)
75                 {{
76                         CheckWriteArrayArguments (array, offset, length);
77                         writer.Write (BF.Array);
78                         WriteStartElement (prefix, localName, namespaceUri);
79                         WriteEndElement ();
80                         WriteArrayRemaining (array, offset, length);
81                 }}
82
83                 void WriteArrayRemaining ({0} [] array, int offset, int length)
84                 {{
85                         writer.Write ((byte) 0x{2:X02}); // ident
86                         writer.WriteFlexibleInt (length);
87                         for (int i = offset; i < offset + length; i++)
88                                 WriteValueContent (array [i]);
89                 }}", ToCSharp (type), type.Name, table [type]);
90
91                 // <note>
92                 // WriteArrayRemaining() is generated, but are modified and moved into 
93                 // XmlBinaryDictionaryWriter. (I keep it open here so that we
94                 // make sure to remove this before compiling. Remove this to get
95                 // it working fine).
96                 // </note>
97
98
99                 }
100                 Console.WriteLine (@"
101         }
102 }");
103         }
104
105         static CodeDomProvider cs = new CSharpCodeProvider ();
106
107         static string ToCSharp (Type type)
108         {
109                 string r = cs.GetTypeOutput (new CodeTypeReference (type));
110                 return r != type.FullName ? r : type.Name;
111         }
112 }
113