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.
29 using System.Runtime.InteropServices;
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)]
38 public sealed class HostProtectionAttribute : CodeAccessSecurityAttribute {
40 private HostProtectionResource _resources;
43 public HostProtectionAttribute (SecurityAction action = SecurityAction.LinkDemand)
45 public HostProtectionAttribute ()
46 : base (SecurityAction.LinkDemand)
50 public HostProtectionAttribute (SecurityAction action)
54 if (action != SecurityAction.LinkDemand) {
55 string msg = String.Format (Locale.GetText ("Only {0} is accepted."), SecurityAction.LinkDemand);
56 throw new ArgumentException (msg, "action");
61 public bool ExternalProcessMgmt {
62 get { return ((_resources & HostProtectionResource.ExternalProcessMgmt) != 0); }
65 _resources |= HostProtectionResource.ExternalProcessMgmt;
68 _resources &= ~HostProtectionResource.ExternalProcessMgmt;
73 public bool ExternalThreading {
74 get { return ((_resources & HostProtectionResource.ExternalThreading) != 0); }
77 _resources |= HostProtectionResource.ExternalThreading;
80 _resources &= ~HostProtectionResource.ExternalThreading;
85 public bool MayLeakOnAbort {
86 get { return ((_resources & HostProtectionResource.MayLeakOnAbort) != 0); }
89 _resources |= HostProtectionResource.MayLeakOnAbort;
92 _resources &= ~HostProtectionResource.MayLeakOnAbort;
98 public bool SecurityInfrastructure {
99 get { return ((_resources & HostProtectionResource.SecurityInfrastructure) != 0); }
102 _resources |= HostProtectionResource.SecurityInfrastructure;
105 _resources &= ~HostProtectionResource.SecurityInfrastructure;
110 public bool SelfAffectingProcessMgmt {
111 get { return ((_resources & HostProtectionResource.SelfAffectingProcessMgmt) != 0); }
114 _resources |= HostProtectionResource.SelfAffectingProcessMgmt;
117 _resources &= ~HostProtectionResource.SelfAffectingProcessMgmt;
122 public bool SelfAffectingThreading {
123 get { return ((_resources & HostProtectionResource.SelfAffectingThreading) != 0); }
126 _resources |= HostProtectionResource.SelfAffectingThreading;
129 _resources &= ~HostProtectionResource.SelfAffectingThreading;
134 public bool SharedState {
135 get { return ((_resources & HostProtectionResource.SharedState) != 0); }
138 _resources |= HostProtectionResource.SharedState;
141 _resources &= ~HostProtectionResource.SharedState;
146 public bool Synchronization {
147 get { return ((_resources & HostProtectionResource.Synchronization) != 0); }
150 _resources |= HostProtectionResource.Synchronization;
153 _resources &= ~HostProtectionResource.Synchronization;
159 get { return ((_resources & HostProtectionResource.UI) != 0); }
162 _resources |= HostProtectionResource.UI;
165 _resources &= ~HostProtectionResource.UI;
170 public HostProtectionResource Resources {
171 get { return _resources; }
172 set { _resources = value; }
176 public override IPermission CreatePermission ()
181 // looks like permission is internal
182 return new HostProtectionPermission (_resources);