[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / System.Security.Policy / ZoneMembershipCondition.cs
blobabaebc274729f6d259a9afd38c34aca8aff037da
1 //
2 // System.Security.Policy.ZoneMembershipCondition.cs
3 //
4 // Authors:
5 // Duncan Mak (duncan@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
8 // (C) 2003, Ximian Inc.
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Globalization;
33 using System.Runtime.InteropServices;
35 namespace System.Security.Policy {
37 [Serializable]
38 [ComVisible (true)]
39 public sealed class ZoneMembershipCondition : IMembershipCondition, IConstantMembershipCondition {
41 private readonly int version = 1;
43 private SecurityZone zone;
45 // so System.Activator.CreateInstance can create an instance...
46 internal ZoneMembershipCondition ()
50 public ZoneMembershipCondition (SecurityZone zone)
52 // we need the validations
53 SecurityZone = zone;
56 public SecurityZone SecurityZone {
57 get { return zone; }
58 set {
59 if (!Enum.IsDefined (typeof (SecurityZone), value)) {
60 throw new ArgumentException (Locale.GetText (
61 "invalid zone"));
63 if (value == SecurityZone.NoZone) {
64 throw new ArgumentException (Locale.GetText (
65 "NoZone isn't valid for membership condition"));
68 zone = value;
72 public bool Check (Evidence evidence)
74 if (evidence == null)
75 return false;
77 IEnumerator e = evidence.GetHostEnumerator ();
78 while (e.MoveNext ()) {
79 Zone z = (e.Current as Zone);
80 if (z != null) {
81 if (z.SecurityZone == zone)
82 return true;
85 return false;
88 public IMembershipCondition Copy ()
90 return new ZoneMembershipCondition (zone);
93 public override bool Equals (object o)
95 ZoneMembershipCondition zmc = (o as ZoneMembershipCondition);
96 if (zmc == null)
97 return false;
98 return (zmc.SecurityZone == zone);
101 public void FromXml (SecurityElement e)
103 FromXml (e, null);
106 public void FromXml (SecurityElement e, PolicyLevel level)
108 MembershipConditionHelper.CheckSecurityElement (e, "e", version, version);
110 string z = e.Attribute ("Zone");
111 if (z != null) {
112 zone = (SecurityZone) Enum.Parse (typeof (SecurityZone), z);
116 public override int GetHashCode ()
118 return zone.GetHashCode ();
121 public override string ToString ()
123 return "Zone - " + zone;
126 public SecurityElement ToXml ()
128 return ToXml (null);
131 public SecurityElement ToXml (PolicyLevel level)
133 // PolicyLevel isn't used as there's no need to resolve NamedPermissionSet references
134 SecurityElement se = MembershipConditionHelper.Element (typeof (ZoneMembershipCondition), version);
135 se.AddAttribute ("Zone", zone.ToString ());
136 return se;