* ReaderWriterLock.cs: Changed some methods to private.
[mono.git] / mcs / class / corlib / System.Security / SecurityException.cs
1 //
2 // System.Security.SecurityException.cs
3 //
4 // Authors:
5 //      Nick Drochak(ndrochak@gol.com)
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) Nick Drochak
9 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
10 //
11
12 using System.Runtime.Serialization;
13 using System.Globalization;
14 using System.Text;
15
16 namespace System.Security {
17
18         [Serializable]
19         public class SecurityException : SystemException {
20
21                 // Fields
22                 string permissionState;
23                 Type permissionType;
24                 private string _granted;
25                 private string _refused;
26
27                 // Properties
28                 public string PermissionState
29                 {
30                         get { return permissionState; }
31                 }
32
33                 public Type PermissionType
34                 {
35                         get { return permissionType; }
36                 }
37 #if ! NET_1_0
38                 public string GrantedSet {
39                         get { return _granted; }
40                 }
41
42                 public string RefusedSet {
43                         get { return _refused; }
44                 }
45 #endif
46                 // Constructors
47                 public SecurityException ()
48                         : base (Locale.GetText ("A security error has been detected."))
49                 {
50                         base.HResult = unchecked ((int)0x8013150A);
51                 }
52
53                 public SecurityException (string message) 
54                         : base (message)
55                 {
56                         base.HResult = unchecked ((int)0x8013150A);
57                 }
58                 
59                 protected SecurityException (SerializationInfo info, StreamingContext context) 
60                         : base (info, context)
61                 {
62                         base.HResult = unchecked ((int)0x8013150A);
63                         permissionState = info.GetString ("permissionState");
64                 }
65                 
66                 public SecurityException (string message, Exception inner) 
67                         : base (message, inner)
68                 {
69                         base.HResult = unchecked ((int)0x8013150A);
70                 }
71                 
72                 public SecurityException (string message, Type type) 
73                         :  base (message) 
74                 {
75                         base.HResult = unchecked ((int)0x8013150A);
76                         permissionType = type;
77                 }
78                 
79                 public SecurityException (string message, Type type, string state) 
80                         : base (message) 
81                 {
82                         base.HResult = unchecked ((int)0x8013150A);
83                         permissionType = type;
84                         permissionState = state;
85                 }
86
87                 internal SecurityException (string message, PermissionSet granted, PermissionSet refused) 
88                         : base (message)
89                 {
90                         base.HResult = unchecked ((int)0x8013150A);
91                         _granted = granted.ToString ();
92                         _refused = refused.ToString ();
93                 }
94
95                 // Methods
96                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
97                 {
98                         base.GetObjectData (info, context);
99                         info.AddValue ("PermissionState", permissionState);
100                 }
101
102                 public override string ToString ()
103                 {
104                         StringBuilder sb = new StringBuilder (base.ToString ());
105                         if (permissionState != null) {
106                                 sb.Append (Environment.NewLine);
107                                 sb.Append ("State: ");
108                                 sb.Append (permissionState);
109                         }
110                         if (permissionType != null) {
111                                 sb.Append (Environment.NewLine);
112                                 sb.Append ("Type: ");
113                                 sb.Append (permissionType.ToString ());
114                         }
115 #if ! NET_1_0
116                         if (_granted != null) {
117                                 sb.Append (Environment.NewLine);
118                                 sb.Append ("Granted: ");
119                                 sb.Append (_granted.ToString ());
120                         }
121                         if (_refused != null) {
122                                 sb.Append (Environment.NewLine);
123                                 sb.Append ("Refused: ");
124                                 sb.Append (_refused.ToString ());
125                         }
126 #endif
127                         return sb.ToString ();
128                 }
129         }
130 }