2 // System.Security.Permissions.HostProtectionAttribute class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 namespace System.Security.Permissions {
33 [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct |
34 AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Delegate,
35 AllowMultiple = true, Inherited = false)]
37 public sealed class HostProtectionAttribute : CodeAccessSecurityAttribute {
39 private HostProtectionResource _resources;
41 public HostProtectionAttribute ()
42 : base (SecurityAction.LinkDemand)
46 public HostProtectionAttribute (SecurityAction action)
49 if (action != SecurityAction.LinkDemand) {
50 string msg = String.Format (Locale.GetText ("Only {0} is accepted."), SecurityAction.LinkDemand);
51 throw new ArgumentException (msg, "action");
56 public bool ExternalProcessMgmt {
57 get { return ((_resources & HostProtectionResource.ExternalProcessMgmt) != 0); }
60 _resources |= HostProtectionResource.ExternalProcessMgmt;
63 _resources &= ~HostProtectionResource.ExternalProcessMgmt;
68 public bool ExternalThreading {
69 get { return ((_resources & HostProtectionResource.ExternalThreading) != 0); }
72 _resources |= HostProtectionResource.ExternalThreading;
75 _resources &= ~HostProtectionResource.ExternalThreading;
80 public bool MayLeakOnAbort {
81 get { return ((_resources & HostProtectionResource.MayLeakOnAbort) != 0); }
84 _resources |= HostProtectionResource.MayLeakOnAbort;
87 _resources &= ~HostProtectionResource.MayLeakOnAbort;
92 public bool SecurityInfrastructure {
93 get { return ((_resources & HostProtectionResource.SecurityInfrastructure) != 0); }
96 _resources |= HostProtectionResource.SecurityInfrastructure;
99 _resources &= ~HostProtectionResource.SecurityInfrastructure;
104 public bool SelfAffectingProcessMgmt {
105 get { return ((_resources & HostProtectionResource.SelfAffectingProcessMgmt) != 0); }
108 _resources |= HostProtectionResource.SelfAffectingProcessMgmt;
111 _resources &= ~HostProtectionResource.SelfAffectingProcessMgmt;
116 public bool SelfAffectingThreading {
117 get { return ((_resources & HostProtectionResource.SelfAffectingThreading) != 0); }
120 _resources |= HostProtectionResource.SelfAffectingThreading;
123 _resources &= ~HostProtectionResource.SelfAffectingThreading;
128 public bool SharedState {
129 get { return ((_resources & HostProtectionResource.SharedState) != 0); }
132 _resources |= HostProtectionResource.SharedState;
135 _resources &= ~HostProtectionResource.SharedState;
140 public bool Synchronization {
141 get { return ((_resources & HostProtectionResource.Synchronization) != 0); }
144 _resources |= HostProtectionResource.Synchronization;
147 _resources &= ~HostProtectionResource.Synchronization;
153 get { return ((_resources & HostProtectionResource.UI) != 0); }
156 _resources |= HostProtectionResource.UI;
159 _resources &= ~HostProtectionResource.UI;
164 public HostProtectionResource Resources {
165 get { return _resources; }
166 set { _resources = value; }
170 public override IPermission CreatePermission ()
172 // looks like permission is internal
173 return new HostProtectionPermission (_resources);