2004-03-08 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
[mono.git] / mcs / class / corlib / System / TypeLoadException.cs
1 //
2 // System.TypeLoadException.cs
3 //
4 // Author:
5 //   Sean MacIsaac (macisaac@ximian.com)
6 //   Duncan Mak  (duncan@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 //
10
11 using System.Globalization;
12 using System.Runtime.Serialization;
13
14 namespace System {
15
16         [Serializable]
17         public class TypeLoadException : SystemException {
18
19                 // Fields
20                 private string msg;
21                 private string type;
22
23                 // Constructors
24                 public TypeLoadException ()
25                         : base (Locale.GetText ("A type load exception has occurred."))
26                 {
27                 }
28
29                 public TypeLoadException (string message)
30                         : base (message)
31                 {
32                 }
33
34                 public TypeLoadException (string message, Exception inner)
35                         : base (message, inner)
36                 {
37                 }
38
39                 protected TypeLoadException (SerializationInfo info, StreamingContext context)
40                         : base (info, context)
41                 {
42                         if (info == null)
43                                 throw new ArgumentNullException ("info is null.");
44
45                         type = info.GetString ("TypeLoadClassName");
46                 }
47
48                 // Properties
49                 public override string Message {
50                         get {
51                                 if (type == null)
52                                         return base.Message;
53
54                                 if (msg == null)
55                                         msg = "Cannot load type '" + type + "'";
56
57                                 return msg;
58                         }
59                 }
60
61                 public string TypeName {
62                         get { 
63                                 if (type == null)
64                                         return "";
65
66                                 return type;
67                         }
68                 }
69
70                 // Methods
71                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
72                 {
73                         if (info == null)
74                                 throw new ArgumentNullException ("info is null.");
75
76                         base.GetObjectData (info, context);
77                         info.AddValue ("TypeLoadClassName", type, typeof (string)); 
78                         info.AddValue ("TypeLoadAssemblyName", "", typeof (string)); 
79                         info.AddValue ("TypeLoadMessageArg", "", typeof (string)); 
80                         info.AddValue ("TypeLoadResourceID", 0, typeof (int)); 
81                 }
82         }
83 }