2 // System.Security.Permissions.HostProtectionAttribute class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004-2005 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 using System.Runtime.InteropServices;
33 namespace System.Security.Permissions {
35 [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct |
36 AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Delegate,
37 AllowMultiple = true, Inherited = false)]
40 public sealed class HostProtectionAttribute : CodeAccessSecurityAttribute {
42 private HostProtectionResource _resources;
44 public HostProtectionAttribute ()
45 : base (SecurityAction.LinkDemand)
49 public HostProtectionAttribute (SecurityAction action)
52 if (action != SecurityAction.LinkDemand) {
53 string msg = String.Format (Locale.GetText ("Only {0} is accepted."), SecurityAction.LinkDemand);
54 throw new ArgumentException (msg, "action");
59 public bool ExternalProcessMgmt {
60 get { return ((_resources & HostProtectionResource.ExternalProcessMgmt) != 0); }
63 _resources |= HostProtectionResource.ExternalProcessMgmt;
66 _resources &= ~HostProtectionResource.ExternalProcessMgmt;
71 public bool ExternalThreading {
72 get { return ((_resources & HostProtectionResource.ExternalThreading) != 0); }
75 _resources |= HostProtectionResource.ExternalThreading;
78 _resources &= ~HostProtectionResource.ExternalThreading;
83 public bool MayLeakOnAbort {
84 get { return ((_resources & HostProtectionResource.MayLeakOnAbort) != 0); }
87 _resources |= HostProtectionResource.MayLeakOnAbort;
90 _resources &= ~HostProtectionResource.MayLeakOnAbort;
96 public bool SecurityInfrastructure {
97 get { return ((_resources & HostProtectionResource.SecurityInfrastructure) != 0); }
100 _resources |= HostProtectionResource.SecurityInfrastructure;
103 _resources &= ~HostProtectionResource.SecurityInfrastructure;
108 public bool SelfAffectingProcessMgmt {
109 get { return ((_resources & HostProtectionResource.SelfAffectingProcessMgmt) != 0); }
112 _resources |= HostProtectionResource.SelfAffectingProcessMgmt;
115 _resources &= ~HostProtectionResource.SelfAffectingProcessMgmt;
120 public bool SelfAffectingThreading {
121 get { return ((_resources & HostProtectionResource.SelfAffectingThreading) != 0); }
124 _resources |= HostProtectionResource.SelfAffectingThreading;
127 _resources &= ~HostProtectionResource.SelfAffectingThreading;
132 public bool SharedState {
133 get { return ((_resources & HostProtectionResource.SharedState) != 0); }
136 _resources |= HostProtectionResource.SharedState;
139 _resources &= ~HostProtectionResource.SharedState;
144 public bool Synchronization {
145 get { return ((_resources & HostProtectionResource.Synchronization) != 0); }
148 _resources |= HostProtectionResource.Synchronization;
151 _resources &= ~HostProtectionResource.Synchronization;
157 get { return ((_resources & HostProtectionResource.UI) != 0); }
160 _resources |= HostProtectionResource.UI;
163 _resources &= ~HostProtectionResource.UI;
168 public HostProtectionResource Resources {
169 get { return _resources; }
170 set { _resources = value; }
174 public override IPermission CreatePermission ()
176 // looks like permission is internal
177 return new HostProtectionPermission (_resources);