**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System.Security.Policy / ApplicationTrustCollection.cs
blob24223f57cbab971691109d9788b4af5993663abe
1 //
2 // System.Security.Policy.ApplicationTrustCollection 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.
29 #if NET_2_0
31 using System.Collections;
32 using System.Globalization;
34 namespace System.Security.Policy {
36 public sealed class ApplicationTrustCollection : CollectionBase {
38 internal ApplicationTrustCollection ()
42 // properties
44 public ApplicationTrust this [int index] {
45 get { return (ApplicationTrust) InnerList [index]; }
46 set { InnerList [index] = value; }
49 // methods
51 public int Add (ApplicationTrust trust)
53 if (trust == null)
54 throw new ArgumentNullException ("trust");
55 if (trust.ApplicationIdentity == null) {
56 throw new ArgumentException (Locale.GetText (
57 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
60 return InnerList.Add (trust);
63 public void AddRange (ApplicationTrust[] trusts)
65 if (trusts == null)
66 throw new ArgumentNullException ("trusts");
68 foreach (ApplicationTrust t in trusts) {
69 if (t.ApplicationIdentity == null) {
70 throw new ArgumentException (Locale.GetText (
71 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
73 InnerList.Add (t);
77 public void AddRange (ApplicationTrustCollection trusts)
79 if (trusts == null)
80 throw new ArgumentNullException ("trusts");
82 foreach (ApplicationTrust t in trusts) {
83 if (t.ApplicationIdentity == null) {
84 throw new ArgumentException (Locale.GetText (
85 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
87 InnerList.Add (t);
91 public bool Contains (ApplicationTrust trust)
93 return (IndexOf (trust) >= 0);
96 public void CopyTo (ApplicationTrust[] array, int index)
98 InnerList.CopyTo (array, index);
101 [MonoTODO ("missing MatchExactVersion")]
102 public ApplicationTrustCollection Find (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch)
104 ApplicationTrustCollection coll = new ApplicationTrustCollection ();
105 foreach (ApplicationTrust t in InnerList) {
106 if (t.ApplicationIdentity.Equals (applicationIdentity)) {
107 switch (versionMatch) {
108 case ApplicationVersionMatch.MatchAllVersions:
109 coll.Add (t);
110 break;
111 case ApplicationVersionMatch.MatchExactVersion:
112 // TODO: version is encoded in a fullname ?
113 break;
117 return coll;
120 public new ApplicationTrustEnumerator GetEnumerator ()
122 return new ApplicationTrustEnumerator (this);
125 public int IndexOf (ApplicationTrust trust)
127 if (trust == null)
128 throw new ArgumentNullException ("trust");
130 for (int i=0; i < InnerList.Count; i++) {
131 if (trust.Equals (InnerList [i]))
132 return i;
134 return -1;
137 public void Insert (int index, ApplicationTrust trust)
139 if (trust == null)
140 throw new ArgumentNullException ("trust");
142 InnerList.Insert (index, trust);
145 public void Remove (ApplicationTrust trust)
147 if (trust == null)
148 throw new ArgumentNullException ("trust");
149 if (trust.ApplicationIdentity == null) {
150 throw new ArgumentException (Locale.GetText (
151 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
154 RemoveAllInstances (trust);
157 [MonoTODO ("missing MatchExactVersion (relies on Find)")]
158 public void Remove (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch)
160 ApplicationTrustCollection coll = Find (applicationIdentity, versionMatch);
161 foreach (ApplicationTrust t in coll) {
162 RemoveAllInstances (t);
166 public void RemoveRange (ApplicationTrust[] trusts)
168 if (trusts == null)
169 throw new ArgumentNullException ("trusts");
171 foreach (ApplicationTrust t in trusts) {
172 RemoveAllInstances (t);
176 public void RemoveRange (ApplicationTrustCollection trusts)
178 if (trusts == null)
179 throw new ArgumentNullException ("trusts");
181 foreach (ApplicationTrust t in trusts) {
182 RemoveAllInstances (t);
186 // helpers
188 internal void RemoveAllInstances (ApplicationTrust trust)
190 for (int i=InnerList.Count - 1; i >= 0; i--) {
191 if (trust.Equals (InnerList [i]))
192 InnerList.RemoveAt (i);
198 #endif