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