1 // System.Security.Policy.Evidence
4 // Sean MacIsaac (macisaac@ximian.com)
5 // Nick Drochak (ndrochak@gol.com)
6 // Jackson Harper (Jackson@LatitudeGeo.com)
8 // (C) 2001 Ximian, Inc.
11 using System.Collections;
13 namespace System.Security.Policy {
17 public sealed class Evidence : ICollection, IEnumerable {
19 private ArrayList hostEvidenceList = new ArrayList ();
20 private ArrayList assemblyEvidenceList = new ArrayList ();
26 public Evidence (Evidence evidence)
32 public Evidence (object[] hostEvidence, object[] assemblyEvidence )
34 if (null != hostEvidence)
35 hostEvidenceList.AddRange (hostEvidence);
36 if (null != assemblyEvidence)
37 assemblyEvidenceList.AddRange (assemblyEvidence);
46 return (hostEvidenceList.Count + assemblyEvidenceList.Count);
50 public bool IsReadOnly {
54 public bool IsSynchronized {
61 throw new NotImplementedException ();
64 throw new NotImplementedException ();
68 public object SyncRoot {
76 public void AddAssembly (object id)
78 assemblyEvidenceList.Add (id);
81 [MonoTODO("If Locked is true and the code that calls this method does not have SecurityPermissionFlag.ControlEvidence a SecurityException should be thrown")]
82 public void AddHost (object id)
84 hostEvidenceList.Add (id);
87 public void CopyTo (Array array, int index)
89 if (hostEvidenceList.Count > 0)
90 hostEvidenceList.CopyTo (array,index);
91 if (assemblyEvidenceList.Count > 0)
92 assemblyEvidenceList.CopyTo (array,index + hostEvidenceList.Count);
95 public IEnumerator GetEnumerator ()
97 return new EvidenceEnumerator (hostEvidenceList.GetEnumerator (),
98 assemblyEvidenceList.GetEnumerator ());
101 public IEnumerator GetAssemblyEnumerator ()
103 return assemblyEvidenceList.GetEnumerator ();
106 public IEnumerator GetHostEnumerator ()
108 return hostEvidenceList.GetEnumerator ();
111 public void Merge (Evidence evidence)
113 IEnumerator hostenum, assemblyenum;
115 hostenum = evidence.GetHostEnumerator ();
116 while( hostenum.MoveNext () ) {
117 AddHost (hostenum.Current);
120 assemblyenum = evidence.GetAssemblyEnumerator ();
121 while( assemblyenum.MoveNext () ) {
122 AddAssembly (assemblyenum.Current);
126 private class EvidenceEnumerator : IEnumerator {
128 private IEnumerator currentEnum, hostEnum, assemblyEnum;
130 public EvidenceEnumerator (IEnumerator hostenum, IEnumerator assemblyenum)
132 this.hostEnum = hostenum;
133 this.assemblyEnum = assemblyenum;
134 currentEnum = hostEnum;
137 public bool MoveNext ()
139 bool ret = currentEnum.MoveNext ();
141 if ( !ret && hostEnum == currentEnum ) {
142 currentEnum = assemblyEnum;
143 ret = assemblyEnum.MoveNext ();
152 assemblyEnum.Reset ();
153 currentEnum = hostEnum;
156 public object Current {
158 return currentEnum.Current;