2 // System.Security.SecurityException.cs
5 // Nick Drochak(ndrochak@gol.com)
6 // Sebastien Pouliot (spouliot@motus.com)
9 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
12 using System.Runtime.Serialization;
13 using System.Globalization;
16 namespace System.Security {
19 public class SecurityException : SystemException {
22 string permissionState;
24 private string _granted;
25 private string _refused;
28 public string PermissionState
30 get { return permissionState; }
33 public Type PermissionType
35 get { return permissionType; }
38 public string GrantedSet {
39 get { return _granted; }
42 public string RefusedSet {
43 get { return _refused; }
47 public SecurityException ()
48 : base (Locale.GetText ("A security error has been detected."))
50 base.HResult = unchecked ((int)0x8013150A);
53 public SecurityException (string message)
56 base.HResult = unchecked ((int)0x8013150A);
59 protected SecurityException (SerializationInfo info, StreamingContext context)
60 : base (info, context)
62 base.HResult = unchecked ((int)0x8013150A);
63 permissionState = info.GetString ("permissionState");
66 public SecurityException (string message, Exception inner)
67 : base (message, inner)
69 base.HResult = unchecked ((int)0x8013150A);
72 public SecurityException (string message, Type type)
75 base.HResult = unchecked ((int)0x8013150A);
76 permissionType = type;
79 public SecurityException (string message, Type type, string state)
82 base.HResult = unchecked ((int)0x8013150A);
83 permissionType = type;
84 permissionState = state;
87 internal SecurityException (string message, PermissionSet granted, PermissionSet refused)
90 base.HResult = unchecked ((int)0x8013150A);
91 _granted = granted.ToString ();
92 _refused = refused.ToString ();
96 public override void GetObjectData (SerializationInfo info, StreamingContext context)
98 base.GetObjectData (info, context);
99 info.AddValue ("PermissionState", permissionState);
102 public override string ToString ()
104 StringBuilder sb = new StringBuilder (base.ToString ());
105 if (permissionState != null) {
106 sb.Append (Environment.NewLine);
107 sb.Append ("State: ");
108 sb.Append (permissionState);
110 if (permissionType != null) {
111 sb.Append (Environment.NewLine);
112 sb.Append ("Type: ");
113 sb.Append (permissionType.ToString ());
116 if (_granted != null) {
117 sb.Append (Environment.NewLine);
118 sb.Append ("Granted: ");
119 sb.Append (_granted.ToString ());
121 if (_refused != null) {
122 sb.Append (Environment.NewLine);
123 sb.Append ("Refused: ");
124 sb.Append (_refused.ToString ());
127 return sb.ToString ();