[mcs] Replace NET_2_1 by MOBILE
[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 using System.Runtime.InteropServices;
30
31 namespace System.Security.Permissions {
32
33         [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct |
34                 AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Delegate, 
35                 AllowMultiple = true, Inherited = false)]
36         [ComVisible (true)]
37         [Serializable]
38         public sealed class HostProtectionAttribute : CodeAccessSecurityAttribute {
39
40                 private HostProtectionResource _resources;
41
42 #if BOOTSTRAP_BASIC
43                 public HostProtectionAttribute (SecurityAction action = SecurityAction.LinkDemand)
44 #else
45                 public HostProtectionAttribute ()
46                         : base (SecurityAction.LinkDemand) 
47                 {
48                 }
49
50                 public HostProtectionAttribute (SecurityAction action)
51 #endif
52                         : base (action) 
53                 {
54                         if (action != SecurityAction.LinkDemand) {
55                                 string msg = String.Format (Locale.GetText ("Only {0} is accepted."), SecurityAction.LinkDemand);
56                                 throw new ArgumentException (msg, "action");
57                         }
58                 }
59
60
61                 public bool ExternalProcessMgmt {
62                         get { return ((_resources & HostProtectionResource.ExternalProcessMgmt) != 0); }
63                         set {
64                                 if (value) {
65                                         _resources |= HostProtectionResource.ExternalProcessMgmt;
66                                 }
67                                 else {
68                                         _resources &= ~HostProtectionResource.ExternalProcessMgmt;
69                                 }
70                         }
71                 }
72
73                 public bool ExternalThreading {
74                         get { return ((_resources & HostProtectionResource.ExternalThreading) != 0); }
75                         set {
76                                 if (value) {
77                                         _resources |= HostProtectionResource.ExternalThreading;
78                                 }
79                                 else {
80                                         _resources &= ~HostProtectionResource.ExternalThreading;
81                                 }
82                         }
83                 }
84
85                 public bool MayLeakOnAbort {
86                         get { return ((_resources & HostProtectionResource.MayLeakOnAbort) != 0); }
87                         set {
88                                 if (value) {
89                                         _resources |= HostProtectionResource.MayLeakOnAbort;
90                                 }
91                                 else {
92                                         _resources &= ~HostProtectionResource.MayLeakOnAbort;
93                                 }
94                         }
95                 }
96
97                 [ComVisible (true)]
98                 public bool SecurityInfrastructure {
99                         get { return ((_resources & HostProtectionResource.SecurityInfrastructure) != 0); }
100                         set {
101                                 if (value) {
102                                         _resources |= HostProtectionResource.SecurityInfrastructure;
103                                 }
104                                 else {
105                                         _resources &= ~HostProtectionResource.SecurityInfrastructure;
106                                 }
107                         }
108                 }
109
110                 public bool SelfAffectingProcessMgmt {
111                         get { return ((_resources & HostProtectionResource.SelfAffectingProcessMgmt) != 0); }
112                         set {
113                                 if (value) {
114                                         _resources |= HostProtectionResource.SelfAffectingProcessMgmt;
115                                 }
116                                 else {
117                                         _resources &= ~HostProtectionResource.SelfAffectingProcessMgmt;
118                                 }
119                         }
120                 }
121
122                 public bool SelfAffectingThreading {
123                         get { return ((_resources & HostProtectionResource.SelfAffectingThreading) != 0); }
124                         set {
125                                 if (value) {
126                                         _resources |= HostProtectionResource.SelfAffectingThreading;
127                                 }
128                                 else {
129                                         _resources &= ~HostProtectionResource.SelfAffectingThreading;
130                                 }
131                         }
132                 }
133
134                 public bool SharedState {
135                         get { return ((_resources & HostProtectionResource.SharedState) != 0); }
136                         set {
137                                 if (value) {
138                                         _resources |= HostProtectionResource.SharedState;
139                                 }
140                                 else {
141                                         _resources &= ~HostProtectionResource.SharedState;
142                                 }
143                         }
144                 }
145
146                 public bool Synchronization {
147                         get { return ((_resources & HostProtectionResource.Synchronization) != 0); }
148                         set {
149                                 if (value) {
150                                         _resources |= HostProtectionResource.Synchronization;
151                                 }
152                                 else {
153                                         _resources &= ~HostProtectionResource.Synchronization;
154                                 }
155                         }
156                 }
157
158                 public bool UI {
159                         get { return ((_resources & HostProtectionResource.UI) != 0); }
160                         set {
161                                 if (value) {
162                                         _resources |= HostProtectionResource.UI;
163                                 }
164                                 else {
165                                         _resources &= ~HostProtectionResource.UI;
166                                 }
167                         }
168                 }
169
170                 public HostProtectionResource Resources {
171                         get { return _resources; }
172                         set { _resources = value; }
173                 }
174
175
176                 public override IPermission CreatePermission ()
177                 {
178 #if MOBILE
179                         return null;
180 #else
181                         // looks like permission is internal
182                         return new HostProtectionPermission (_resources);
183 #endif
184                 }
185         }
186 }
187