[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mcs / class / System.Runtime.Serialization / writer-method-gen.cs
1 // mono writer-method-gen.exe > System.Xml/XmlDictionaryWriterAutoGen.cs
2 using System;
3 using System.Globalization;
4 using System.CodeDom;
5 using System.CodeDom.Compiler;
6 using Microsoft.CSharp;
7
8 public class Generator
9 {
10         public static void Main ()
11         {
12                 Console.Out.NewLine = "\n";
13                 Type [] types = new Type [] {
14                         typeof (bool), typeof (DateTime), typeof (decimal), typeof (double),
15                         typeof (Guid), typeof (short), typeof (int), typeof (long), typeof (float), typeof (TimeSpan) };
16
17                 Console.WriteLine (@"
18 using System;
19
20 namespace System.Xml
21 {
22         public abstract partial class XmlDictionaryWriter : XmlWriter
23         {
24                 void CheckWriteArrayArguments (Array array, int offset, int length)
25                 {
26                         if (array == null)
27                                 throw new ArgumentNullException (""array"");
28                         if (offset < 0)
29                                 throw new ArgumentOutOfRangeException (""offset is negative"");
30                         if (offset > array.Length)
31                                 throw new ArgumentOutOfRangeException (""offset exceeds the length of the destination array"");
32                         if (length < 0)
33                                 throw new ArgumentOutOfRangeException (""length is negative"");
34                         if (length > array.Length - offset)
35                                 throw new ArgumentOutOfRangeException (""length + offset exceeds the length of the destination array"");
36                 }
37
38                 void CheckDictionaryStringArgs (XmlDictionaryString localName, XmlDictionaryString namespaceUri)
39                 {
40                         if (localName == null)
41                                 throw new ArgumentNullException (""localName"");
42                         if (namespaceUri == null)
43                                 throw new ArgumentNullException (""namespaceUri"");
44                 }
45 ");
46
47                 foreach (Type type in types) {
48                         Console.WriteLine (@"
49                 public virtual void WriteArray (string prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri, {0} [] array, int offset, int length)
50                 {{
51                         CheckDictionaryStringArgs (localName, namespaceUri);
52                         WriteArray (prefix, localName.Value, namespaceUri.Value, array, offset, length);
53                 }}
54
55                 public virtual void WriteArray (string prefix, string localName, string namespaceUri, {0} [] array, int offset, int length)
56                 {{
57                         CheckWriteArrayArguments (array, offset, length);
58                         for (int i = 0; i < length; i++) {{
59                                 WriteStartElement (prefix, localName, namespaceUri);
60                                 WriteValue (array [offset + i]);
61                                 WriteEndElement ();
62                         }}
63
64                 }}", ToCSharp (type), type.Name);
65
66                 }
67                 Console.WriteLine (@"
68         }
69 }");
70         }
71
72         static CodeDomProvider cs = new CSharpCodeProvider ();
73
74         static string ToCSharp (Type type)
75         {
76                 string r = cs.GetTypeOutput (new CodeTypeReference (type));
77                 return r != type.FullName ? r : type.Name;
78         }
79 }
80