Switch to compiler-tester
[mono.git] / mcs / class / corlib / System.Security.Permissions / HostProtectionAttribute.cs
1 //
2 // System.Security.Permissions.HostProtectionAttribute class
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if NET_2_0
30
31 using System.Runtime.InteropServices;
32
33 namespace System.Security.Permissions {
34
35         [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct |
36                 AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Delegate, 
37                 AllowMultiple = true, Inherited = false)]
38         [ComVisible (true)]
39         [Serializable]
40         public sealed class HostProtectionAttribute : CodeAccessSecurityAttribute {
41
42                 private HostProtectionResource _resources;
43
44                 public HostProtectionAttribute ()
45                         : base (SecurityAction.LinkDemand) 
46                 {
47                 }
48
49                 public HostProtectionAttribute (SecurityAction action)
50                         : base (action) 
51                 {
52                         if (action != SecurityAction.LinkDemand) {
53                                 string msg = String.Format (Locale.GetText ("Only {0} is accepted."), SecurityAction.LinkDemand);
54                                 throw new ArgumentException (msg, "action");
55                         }
56                 }
57
58
59                 public bool ExternalProcessMgmt {
60                         get { return ((_resources & HostProtectionResource.ExternalProcessMgmt) != 0); }
61                         set {
62                                 if (value) {
63                                         _resources |= HostProtectionResource.ExternalProcessMgmt;
64                                 }
65                                 else {
66                                         _resources &= ~HostProtectionResource.ExternalProcessMgmt;
67                                 }
68                         }
69                 }
70
71                 public bool ExternalThreading {
72                         get { return ((_resources & HostProtectionResource.ExternalThreading) != 0); }
73                         set {
74                                 if (value) {
75                                         _resources |= HostProtectionResource.ExternalThreading;
76                                 }
77                                 else {
78                                         _resources &= ~HostProtectionResource.ExternalThreading;
79                                 }
80                         }
81                 }
82
83                 public bool MayLeakOnAbort {
84                         get { return ((_resources & HostProtectionResource.MayLeakOnAbort) != 0); }
85                         set {
86                                 if (value) {
87                                         _resources |= HostProtectionResource.MayLeakOnAbort;
88                                 }
89                                 else {
90                                         _resources &= ~HostProtectionResource.MayLeakOnAbort;
91                                 }
92                         }
93                 }
94
95                 [ComVisible (true)]
96                 public bool SecurityInfrastructure {
97                         get { return ((_resources & HostProtectionResource.SecurityInfrastructure) != 0); }
98                         set {
99                                 if (value) {
100                                         _resources |= HostProtectionResource.SecurityInfrastructure;
101                                 }
102                                 else {
103                                         _resources &= ~HostProtectionResource.SecurityInfrastructure;
104                                 }
105                         }
106                 }
107
108                 public bool SelfAffectingProcessMgmt {
109                         get { return ((_resources & HostProtectionResource.SelfAffectingProcessMgmt) != 0); }
110                         set {
111                                 if (value) {
112                                         _resources |= HostProtectionResource.SelfAffectingProcessMgmt;
113                                 }
114                                 else {
115                                         _resources &= ~HostProtectionResource.SelfAffectingProcessMgmt;
116                                 }
117                         }
118                 }
119
120                 public bool SelfAffectingThreading {
121                         get { return ((_resources & HostProtectionResource.SelfAffectingThreading) != 0); }
122                         set {
123                                 if (value) {
124                                         _resources |= HostProtectionResource.SelfAffectingThreading;
125                                 }
126                                 else {
127                                         _resources &= ~HostProtectionResource.SelfAffectingThreading;
128                                 }
129                         }
130                 }
131
132                 public bool SharedState {
133                         get { return ((_resources & HostProtectionResource.SharedState) != 0); }
134                         set {
135                                 if (value) {
136                                         _resources |= HostProtectionResource.SharedState;
137                                 }
138                                 else {
139                                         _resources &= ~HostProtectionResource.SharedState;
140                                 }
141                         }
142                 }
143
144                 public bool Synchronization {
145                         get { return ((_resources & HostProtectionResource.Synchronization) != 0); }
146                         set {
147                                 if (value) {
148                                         _resources |= HostProtectionResource.Synchronization;
149                                 }
150                                 else {
151                                         _resources &= ~HostProtectionResource.Synchronization;
152                                 }
153                         }
154                 }
155
156                 public bool UI {
157                         get { return ((_resources & HostProtectionResource.UI) != 0); }
158                         set {
159                                 if (value) {
160                                         _resources |= HostProtectionResource.UI;
161                                 }
162                                 else {
163                                         _resources &= ~HostProtectionResource.UI;
164                                 }
165                         }
166                 }
167
168                 public HostProtectionResource Resources {
169                         get { return _resources; }
170                         set { _resources = value; }
171                 }
172
173
174                 public override IPermission CreatePermission ()
175                 {
176                         // looks like permission is internal
177                         return new HostProtectionPermission (_resources);
178                 }
179         }
180 }
181
182 #endif