mscorlib(4.0.0.0) API with additions
Evidence.cs
1 using System.Collections;
3 using System.IO;
4 using System.Reflection;
10 using System.Threading;
11 
12 namespace System.Security.Policy
13 {
15  [Serializable]
16  [ComVisible(true)]
17  public sealed class Evidence : ICollection, IEnumerable
18  {
19  private enum DuplicateEvidenceAction
20  {
21  Throw,
22  Merge,
23  SelectNewObject
24  }
25 
26  private class EvidenceLockHolder : IDisposable
27  {
28  public enum LockType
29  {
30  Reader,
31  Writer
32  }
33 
34  private Evidence m_target;
35 
36  private LockType m_lockType;
37 
38  public EvidenceLockHolder(Evidence target, LockType lockType)
39  {
40  m_target = target;
41  m_lockType = lockType;
42  if (m_lockType == LockType.Reader)
43  {
44  m_target.AcquireReaderLock();
45  }
46  else
47  {
48  m_target.AcquireWriterlock();
49  }
50  }
51 
52  public void Dispose()
53  {
54  if (m_lockType == LockType.Reader && m_target.IsReaderLockHeld)
55  {
56  m_target.ReleaseReaderLock();
57  }
58  else if (m_lockType == LockType.Writer && m_target.IsWriterLockHeld)
59  {
60  m_target.ReleaseWriterLock();
61  }
62  }
63  }
64 
65  private class EvidenceUpgradeLockHolder : IDisposable
66  {
67  private Evidence m_target;
68 
69  private LockCookie m_cookie;
70 
71  public EvidenceUpgradeLockHolder(Evidence target)
72  {
73  m_target = target;
74  m_cookie = m_target.UpgradeToWriterLock();
75  }
76 
77  public void Dispose()
78  {
79  if (m_target.IsWriterLockHeld)
80  {
81  m_target.DowngradeFromWriterLock(ref m_cookie);
82  }
83  }
84  }
85 
86  internal sealed class RawEvidenceEnumerator : IEnumerator<EvidenceBase>, IDisposable, IEnumerator
87  {
88  private Evidence m_evidence;
89 
90  private bool m_hostEnumerator;
91 
92  private uint m_evidenceVersion;
93 
94  private Type[] m_evidenceTypes;
95 
96  private int m_typeIndex;
97 
98  private EvidenceBase m_currentEvidence;
99 
100  private static volatile List<Type> s_expensiveEvidence;
101 
102  public EvidenceBase Current
103  {
104  get
105  {
106  if (m_evidence.m_version != m_evidenceVersion)
107  {
108  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumFailedVersion"));
109  }
110  return m_currentEvidence;
111  }
112  }
113 
114  object IEnumerator.Current
115  {
116  get
117  {
118  if (m_evidence.m_version != m_evidenceVersion)
119  {
120  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumFailedVersion"));
121  }
122  return m_currentEvidence;
123  }
124  }
125 
126  private static List<Type> ExpensiveEvidence
127  {
128  get
129  {
130  if (s_expensiveEvidence == null)
131  {
132  List<Type> list = new List<Type>();
133  list.Add(typeof(Hash));
134  list.Add(typeof(Publisher));
135  s_expensiveEvidence = list;
136  }
137  return s_expensiveEvidence;
138  }
139  }
140 
141  public RawEvidenceEnumerator(Evidence evidence, IEnumerable<Type> evidenceTypes, bool hostEnumerator)
142  {
143  m_evidence = evidence;
144  m_hostEnumerator = hostEnumerator;
145  m_evidenceTypes = GenerateEvidenceTypes(evidence, evidenceTypes, hostEnumerator);
146  m_evidenceVersion = evidence.m_version;
147  Reset();
148  }
149 
150  public void Dispose()
151  {
152  }
153 
154  private static Type[] GenerateEvidenceTypes(Evidence evidence, IEnumerable<Type> evidenceTypes, bool hostEvidence)
155  {
156  List<Type> list = new List<Type>();
157  List<Type> list2 = new List<Type>();
158  List<Type> list3 = new List<Type>(ExpensiveEvidence.Count);
159  foreach (Type evidenceType in evidenceTypes)
160  {
161  EvidenceTypeDescriptor evidenceTypeDescriptor = evidence.GetEvidenceTypeDescriptor(evidenceType);
162  if ((hostEvidence && evidenceTypeDescriptor.HostEvidence != null) || (!hostEvidence && evidenceTypeDescriptor.AssemblyEvidence != null))
163  {
164  list.Add(evidenceType);
165  }
166  else if (ExpensiveEvidence.Contains(evidenceType))
167  {
168  list3.Add(evidenceType);
169  }
170  else
171  {
172  list2.Add(evidenceType);
173  }
174  }
175  Type[] array = new Type[list.Count + list2.Count + list3.Count];
176  list.CopyTo(array, 0);
177  list2.CopyTo(array, list.Count);
178  list3.CopyTo(array, list.Count + list2.Count);
179  return array;
180  }
181 
182  [SecuritySafeCritical]
183  public bool MoveNext()
184  {
185  using (new EvidenceLockHolder(m_evidence, EvidenceLockHolder.LockType.Reader))
186  {
187  if (m_evidence.m_version != m_evidenceVersion)
188  {
189  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumFailedVersion"));
190  }
191  m_currentEvidence = null;
192  do
193  {
194  m_typeIndex++;
195  if (m_typeIndex < m_evidenceTypes.Length)
196  {
197  if (m_hostEnumerator)
198  {
199  m_currentEvidence = m_evidence.GetHostEvidenceNoLock(m_evidenceTypes[m_typeIndex]);
200  }
201  else
202  {
203  m_currentEvidence = m_evidence.GetAssemblyEvidenceNoLock(m_evidenceTypes[m_typeIndex]);
204  }
205  }
206  }
207  while (m_typeIndex < m_evidenceTypes.Length && m_currentEvidence == null);
208  }
209  return m_currentEvidence != null;
210  }
211 
212  public void Reset()
213  {
214  if (m_evidence.m_version != m_evidenceVersion)
215  {
216  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumFailedVersion"));
217  }
218  m_typeIndex = -1;
219  m_currentEvidence = null;
220  }
221  }
222 
223  private sealed class EvidenceEnumerator : IEnumerator
224  {
225  [Flags]
226  internal enum Category
227  {
228  Host = 0x1,
229  Assembly = 0x2
230  }
231 
232  private Evidence m_evidence;
233 
234  private Category m_category;
235 
236  private Stack m_enumerators;
237 
238  private object m_currentEvidence;
239 
240  public object Current => m_currentEvidence;
241 
242  private IEnumerator CurrentEnumerator
243  {
244  get
245  {
246  if (m_enumerators.Count <= 0)
247  {
248  return null;
249  }
250  return m_enumerators.Peek() as IEnumerator;
251  }
252  }
253 
254  internal EvidenceEnumerator(Evidence evidence, Category category)
255  {
256  m_evidence = evidence;
257  m_category = category;
258  ResetNoLock();
259  }
260 
261  public bool MoveNext()
262  {
263  IEnumerator currentEnumerator = CurrentEnumerator;
264  if (currentEnumerator == null)
265  {
266  m_currentEvidence = null;
267  return false;
268  }
269  if (currentEnumerator.MoveNext())
270  {
271  LegacyEvidenceWrapper legacyEvidenceWrapper = currentEnumerator.Current as LegacyEvidenceWrapper;
272  LegacyEvidenceList legacyEvidenceList = currentEnumerator.Current as LegacyEvidenceList;
273  if (legacyEvidenceWrapper != null)
274  {
275  m_currentEvidence = legacyEvidenceWrapper.EvidenceObject;
276  }
277  else if (legacyEvidenceList != null)
278  {
279  IEnumerator enumerator = legacyEvidenceList.GetEnumerator();
280  m_enumerators.Push(enumerator);
281  MoveNext();
282  }
283  else
284  {
285  m_currentEvidence = currentEnumerator.Current;
286  }
287  return true;
288  }
289  m_enumerators.Pop();
290  return MoveNext();
291  }
292 
293  public void Reset()
294  {
295  using (new EvidenceLockHolder(m_evidence, EvidenceLockHolder.LockType.Reader))
296  {
297  ResetNoLock();
298  }
299  }
300 
301  private void ResetNoLock()
302  {
303  m_currentEvidence = null;
304  m_enumerators = new Stack();
305  if ((m_category & Category.Host) == Category.Host)
306  {
307  m_enumerators.Push(m_evidence.GetRawHostEvidenceEnumerator());
308  }
309  if ((m_category & Category.Assembly) == Category.Assembly)
310  {
311  m_enumerators.Push(m_evidence.GetRawAssemblyEvidenceEnumerator());
312  }
313  }
314  }
315 
316  [OptionalField(VersionAdded = 4)]
317  private Dictionary<Type, EvidenceTypeDescriptor> m_evidence;
318 
319  [OptionalField(VersionAdded = 4)]
320  private bool m_deserializedTargetEvidence;
321 
322  private volatile ArrayList m_hostList;
323 
324  private volatile ArrayList m_assemblyList;
325 
326  [NonSerialized]
327  private ReaderWriterLock m_evidenceLock;
328 
329  [NonSerialized]
330  private uint m_version;
331 
332  [NonSerialized]
333  private IRuntimeEvidenceFactory m_target;
334 
335  private bool m_locked;
336 
337  [NonSerialized]
338  private WeakReference m_cloneOrigin;
339 
340  private static volatile Type[] s_runtimeEvidenceTypes;
341 
342  private const int LockTimeout = 5000;
343 
344  internal static Type[] RuntimeEvidenceTypes
345  {
346  get
347  {
348  if (s_runtimeEvidenceTypes == null)
349  {
350  Type[] array = new Type[10]
351  {
352  typeof(ActivationArguments),
353  typeof(ApplicationDirectory),
354  typeof(ApplicationTrust),
355  typeof(GacInstalled),
356  typeof(Hash),
357  typeof(Publisher),
358  typeof(Site),
359  typeof(StrongName),
360  typeof(Url),
361  typeof(Zone)
362  };
363  if (AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
364  {
365  int num = array.Length;
366  Array.Resize(ref array, num + 1);
367  array[num] = typeof(PermissionRequestEvidence);
368  }
369  s_runtimeEvidenceTypes = array;
370  }
371  return s_runtimeEvidenceTypes;
372  }
373  }
374 
375  private bool IsReaderLockHeld
376  {
377  get
378  {
379  if (m_evidenceLock != null)
380  {
381  return m_evidenceLock.IsReaderLockHeld;
382  }
383  return true;
384  }
385  }
386 
387  private bool IsWriterLockHeld
388  {
389  get
390  {
391  if (m_evidenceLock != null)
392  {
393  return m_evidenceLock.IsWriterLockHeld;
394  }
395  return true;
396  }
397  }
398 
399  internal bool IsUnmodified => m_version == 0;
400 
404  public bool Locked
405  {
406  get
407  {
408  return m_locked;
409  }
410  [SecuritySafeCritical]
411  set
412  {
413  if (!value)
414  {
415  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
416  m_locked = false;
417  }
418  else
419  {
420  m_locked = true;
421  }
422  }
423  }
424 
425  internal IRuntimeEvidenceFactory Target
426  {
427  get
428  {
429  return m_target;
430  }
431  [SecurityCritical]
432  set
433  {
434  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
435  {
436  m_target = value;
437  QueryHostForPossibleEvidenceTypes();
438  }
439  }
440  }
441 
444  [Obsolete("Evidence should not be treated as an ICollection. Please use GetHostEnumerator and GetAssemblyEnumerator to iterate over the evidence to collect a count.")]
445  public int Count
446  {
447  get
448  {
449  int num = 0;
450  IEnumerator hostEnumerator = GetHostEnumerator();
451  while (hostEnumerator.MoveNext())
452  {
453  num++;
454  }
455  IEnumerator assemblyEnumerator = GetAssemblyEnumerator();
456  while (assemblyEnumerator.MoveNext())
457  {
458  num++;
459  }
460  return num;
461  }
462  }
463 
464  [ComVisible(false)]
465  internal int RawCount
466  {
467  get
468  {
469  int num = 0;
470  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
471  {
472  foreach (Type item in new List<Type>(m_evidence.Keys))
473  {
474  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(item);
475  if (evidenceTypeDescriptor != null)
476  {
477  if (evidenceTypeDescriptor.AssemblyEvidence != null)
478  {
479  num++;
480  }
481  if (evidenceTypeDescriptor.HostEvidence != null)
482  {
483  num++;
484  }
485  }
486  }
487  return num;
488  }
489  }
490  }
491 
494  public object SyncRoot => this;
495 
498  public bool IsSynchronized => true;
499 
502  public bool IsReadOnly => false;
503 
505  public Evidence()
506  {
507  m_evidence = new Dictionary<Type, EvidenceTypeDescriptor>();
508  m_evidenceLock = new ReaderWriterLock();
509  }
510 
514  public Evidence(Evidence evidence)
515  {
516  m_evidence = new Dictionary<Type, EvidenceTypeDescriptor>();
517  if (evidence != null)
518  {
519  using (new EvidenceLockHolder(evidence, EvidenceLockHolder.LockType.Reader))
520  {
521  foreach (KeyValuePair<Type, EvidenceTypeDescriptor> item in evidence.m_evidence)
522  {
523  EvidenceTypeDescriptor evidenceTypeDescriptor = item.Value;
524  if (evidenceTypeDescriptor != null)
525  {
526  evidenceTypeDescriptor = evidenceTypeDescriptor.Clone();
527  }
528  m_evidence[item.Key] = evidenceTypeDescriptor;
529  }
530  m_target = evidence.m_target;
531  m_locked = evidence.m_locked;
532  m_deserializedTargetEvidence = evidence.m_deserializedTargetEvidence;
533  if (evidence.Target != null)
534  {
535  m_cloneOrigin = new WeakReference(evidence);
536  }
537  }
538  }
539  m_evidenceLock = new ReaderWriterLock();
540  }
541 
545  [Obsolete("This constructor is obsolete. Please use the constructor which takes arrays of EvidenceBase instead.")]
546  public Evidence(object[] hostEvidence, object[] assemblyEvidence)
547  {
548  m_evidence = new Dictionary<Type, EvidenceTypeDescriptor>();
549  if (hostEvidence != null)
550  {
551  foreach (object id in hostEvidence)
552  {
553  AddHost(id);
554  }
555  }
556  if (assemblyEvidence != null)
557  {
558  foreach (object id2 in assemblyEvidence)
559  {
560  AddAssembly(id2);
561  }
562  }
563  m_evidenceLock = new ReaderWriterLock();
564  }
565 
569  public Evidence(EvidenceBase[] hostEvidence, EvidenceBase[] assemblyEvidence)
570  {
571  m_evidence = new Dictionary<Type, EvidenceTypeDescriptor>();
572  if (hostEvidence != null)
573  {
574  foreach (EvidenceBase evidence in hostEvidence)
575  {
576  AddHostEvidence(evidence, GetEvidenceIndexType(evidence), DuplicateEvidenceAction.Throw);
577  }
578  }
579  if (assemblyEvidence != null)
580  {
581  foreach (EvidenceBase evidence2 in assemblyEvidence)
582  {
583  AddAssemblyEvidence(evidence2, GetEvidenceIndexType(evidence2), DuplicateEvidenceAction.Throw);
584  }
585  }
586  m_evidenceLock = new ReaderWriterLock();
587  }
588 
589  [SecuritySafeCritical]
590  internal Evidence(IRuntimeEvidenceFactory target)
591  {
592  m_evidence = new Dictionary<Type, EvidenceTypeDescriptor>();
593  m_target = target;
594  Type[] runtimeEvidenceTypes = RuntimeEvidenceTypes;
595  foreach (Type key in runtimeEvidenceTypes)
596  {
597  m_evidence[key] = null;
598  }
599  QueryHostForPossibleEvidenceTypes();
600  m_evidenceLock = new ReaderWriterLock();
601  }
602 
603  private void AcquireReaderLock()
604  {
605  if (m_evidenceLock != null)
606  {
607  m_evidenceLock.AcquireReaderLock(5000);
608  }
609  }
610 
611  private void AcquireWriterlock()
612  {
613  if (m_evidenceLock != null)
614  {
615  m_evidenceLock.AcquireWriterLock(5000);
616  }
617  }
618 
619  private void DowngradeFromWriterLock(ref LockCookie lockCookie)
620  {
621  if (m_evidenceLock != null)
622  {
623  m_evidenceLock.DowngradeFromWriterLock(ref lockCookie);
624  }
625  }
626 
627  private LockCookie UpgradeToWriterLock()
628  {
629  if (m_evidenceLock == null)
630  {
631  return default(LockCookie);
632  }
633  return m_evidenceLock.UpgradeToWriterLock(5000);
634  }
635 
636  private void ReleaseReaderLock()
637  {
638  if (m_evidenceLock != null)
639  {
640  m_evidenceLock.ReleaseReaderLock();
641  }
642  }
643 
644  private void ReleaseWriterLock()
645  {
646  if (m_evidenceLock != null)
647  {
648  m_evidenceLock.ReleaseWriterLock();
649  }
650  }
651 
658  [Obsolete("This method is obsolete. Please use AddHostEvidence instead.")]
659  [SecuritySafeCritical]
660  public void AddHost(object id)
661  {
662  if (id == null)
663  {
664  throw new ArgumentNullException("id");
665  }
666  if (!id.GetType().IsSerializable)
667  {
668  throw new ArgumentException(Environment.GetResourceString("Policy_EvidenceMustBeSerializable"), "id");
669  }
670  if (m_locked)
671  {
672  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
673  }
674  EvidenceBase evidence = WrapLegacyEvidence(id);
675  Type evidenceIndexType = GetEvidenceIndexType(evidence);
676  AddHostEvidence(evidence, evidenceIndexType, DuplicateEvidenceAction.Merge);
677  }
678 
685  [Obsolete("This method is obsolete. Please use AddAssemblyEvidence instead.")]
686  public void AddAssembly(object id)
687  {
688  if (id == null)
689  {
690  throw new ArgumentNullException("id");
691  }
692  if (!id.GetType().IsSerializable)
693  {
694  throw new ArgumentException(Environment.GetResourceString("Policy_EvidenceMustBeSerializable"), "id");
695  }
696  EvidenceBase evidence = WrapLegacyEvidence(id);
697  Type evidenceIndexType = GetEvidenceIndexType(evidence);
698  AddAssemblyEvidence(evidence, evidenceIndexType, DuplicateEvidenceAction.Merge);
699  }
700 
709  [ComVisible(false)]
710  public void AddAssemblyEvidence<T>(T evidence) where T : EvidenceBase
711  {
712  if (evidence == null)
713  {
714  throw new ArgumentNullException("evidence");
715  }
716  Type evidenceType = typeof(T);
717  if (typeof(T) == typeof(EvidenceBase) || evidence is ILegacyEvidenceAdapter)
718  {
719  evidenceType = GetEvidenceIndexType(evidence);
720  }
721  AddAssemblyEvidence(evidence, evidenceType, DuplicateEvidenceAction.Throw);
722  }
723 
724  private void AddAssemblyEvidence(EvidenceBase evidence, Type evidenceType, DuplicateEvidenceAction duplicateAction)
725  {
726  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
727  {
728  AddAssemblyEvidenceNoLock(evidence, evidenceType, duplicateAction);
729  }
730  }
731 
732  private void AddAssemblyEvidenceNoLock(EvidenceBase evidence, Type evidenceType, DuplicateEvidenceAction duplicateAction)
733  {
734  DeserializeTargetEvidence();
735  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(evidenceType, addIfNotExist: true);
736  m_version++;
737  if (evidenceTypeDescriptor.AssemblyEvidence == null)
738  {
739  evidenceTypeDescriptor.AssemblyEvidence = evidence;
740  }
741  else
742  {
743  evidenceTypeDescriptor.AssemblyEvidence = HandleDuplicateEvidence(evidenceTypeDescriptor.AssemblyEvidence, evidence, duplicateAction);
744  }
745  }
746 
753  [ComVisible(false)]
754  public void AddHostEvidence<T>(T evidence) where T : EvidenceBase
755  {
756  if (evidence == null)
757  {
758  throw new ArgumentNullException("evidence");
759  }
760  Type evidenceType = typeof(T);
761  if (typeof(T) == typeof(EvidenceBase) || evidence is ILegacyEvidenceAdapter)
762  {
763  evidenceType = GetEvidenceIndexType(evidence);
764  }
765  AddHostEvidence(evidence, evidenceType, DuplicateEvidenceAction.Throw);
766  }
767 
768  [SecuritySafeCritical]
769  private void AddHostEvidence(EvidenceBase evidence, Type evidenceType, DuplicateEvidenceAction duplicateAction)
770  {
771  if (Locked)
772  {
773  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
774  }
775  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
776  {
777  AddHostEvidenceNoLock(evidence, evidenceType, duplicateAction);
778  }
779  }
780 
781  private void AddHostEvidenceNoLock(EvidenceBase evidence, Type evidenceType, DuplicateEvidenceAction duplicateAction)
782  {
783  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(evidenceType, addIfNotExist: true);
784  m_version++;
785  if (evidenceTypeDescriptor.HostEvidence == null)
786  {
787  evidenceTypeDescriptor.HostEvidence = evidence;
788  }
789  else
790  {
791  evidenceTypeDescriptor.HostEvidence = HandleDuplicateEvidence(evidenceTypeDescriptor.HostEvidence, evidence, duplicateAction);
792  }
793  }
794 
795  [SecurityCritical]
796  private void QueryHostForPossibleEvidenceTypes()
797  {
798  if (AppDomain.CurrentDomain.DomainManager == null)
799  {
800  return;
801  }
802  HostSecurityManager hostSecurityManager = AppDomain.CurrentDomain.DomainManager.HostSecurityManager;
803  if (hostSecurityManager == null)
804  {
805  return;
806  }
807  Type[] array = null;
808  AppDomain appDomain = m_target.Target as AppDomain;
809  Assembly assembly = m_target.Target as Assembly;
810  if (assembly != null && (hostSecurityManager.Flags & HostSecurityManagerOptions.HostAssemblyEvidence) == HostSecurityManagerOptions.HostAssemblyEvidence)
811  {
812  array = hostSecurityManager.GetHostSuppliedAssemblyEvidenceTypes(assembly);
813  }
814  else if (appDomain != null && (hostSecurityManager.Flags & HostSecurityManagerOptions.HostAppDomainEvidence) == HostSecurityManagerOptions.HostAppDomainEvidence)
815  {
816  array = hostSecurityManager.GetHostSuppliedAppDomainEvidenceTypes();
817  }
818  if (array != null)
819  {
820  Type[] array2 = array;
821  foreach (Type evidenceType in array2)
822  {
823  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(evidenceType, addIfNotExist: true);
824  evidenceTypeDescriptor.HostCanGenerate = true;
825  }
826  }
827  }
828 
829  private static Type GetEvidenceIndexType(EvidenceBase evidence)
830  {
831  ILegacyEvidenceAdapter legacyEvidenceAdapter = evidence as ILegacyEvidenceAdapter;
832  if (legacyEvidenceAdapter != null)
833  {
834  return legacyEvidenceAdapter.EvidenceType;
835  }
836  return evidence.GetType();
837  }
838 
839  internal EvidenceTypeDescriptor GetEvidenceTypeDescriptor(Type evidenceType)
840  {
841  return GetEvidenceTypeDescriptor(evidenceType, addIfNotExist: false);
842  }
843 
844  private EvidenceTypeDescriptor GetEvidenceTypeDescriptor(Type evidenceType, bool addIfNotExist)
845  {
846  EvidenceTypeDescriptor value = null;
847  if (!m_evidence.TryGetValue(evidenceType, out value) && !addIfNotExist)
848  {
849  return null;
850  }
851  if (value == null)
852  {
853  value = new EvidenceTypeDescriptor();
854  bool flag = false;
855  LockCookie lockCookie = default(LockCookie);
856  try
857  {
858  if (!IsWriterLockHeld)
859  {
860  lockCookie = UpgradeToWriterLock();
861  flag = true;
862  }
863  m_evidence[evidenceType] = value;
864  return value;
865  }
866  finally
867  {
868  if (flag)
869  {
870  DowngradeFromWriterLock(ref lockCookie);
871  }
872  }
873  }
874  return value;
875  }
876 
877  private static EvidenceBase HandleDuplicateEvidence(EvidenceBase original, EvidenceBase duplicate, DuplicateEvidenceAction action)
878  {
879  switch (action)
880  {
881  case DuplicateEvidenceAction.Throw:
882  throw new InvalidOperationException(Environment.GetResourceString("Policy_DuplicateEvidence", duplicate.GetType().FullName));
883  case DuplicateEvidenceAction.SelectNewObject:
884  return duplicate;
885  case DuplicateEvidenceAction.Merge:
886  {
887  LegacyEvidenceList legacyEvidenceList = original as LegacyEvidenceList;
888  if (legacyEvidenceList == null)
889  {
890  legacyEvidenceList = new LegacyEvidenceList();
891  legacyEvidenceList.Add(original);
892  }
893  legacyEvidenceList.Add(duplicate);
894  return legacyEvidenceList;
895  }
896  default:
897  return null;
898  }
899  }
900 
901  private static EvidenceBase WrapLegacyEvidence(object evidence)
902  {
903  EvidenceBase evidenceBase = evidence as EvidenceBase;
904  if (evidenceBase == null)
905  {
906  evidenceBase = new LegacyEvidenceWrapper(evidence);
907  }
908  return evidenceBase;
909  }
910 
911  private static object UnwrapEvidence(EvidenceBase evidence)
912  {
913  ILegacyEvidenceAdapter legacyEvidenceAdapter = evidence as ILegacyEvidenceAdapter;
914  if (legacyEvidenceAdapter != null)
915  {
916  return legacyEvidenceAdapter.EvidenceObject;
917  }
918  return evidence;
919  }
920 
926  [SecuritySafeCritical]
927  public void Merge(Evidence evidence)
928  {
929  if (evidence != null)
930  {
931  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
932  {
933  bool flag = false;
934  IEnumerator hostEnumerator = evidence.GetHostEnumerator();
935  while (hostEnumerator.MoveNext())
936  {
937  if (Locked && !flag)
938  {
939  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
940  flag = true;
941  }
942  Type type = hostEnumerator.Current.GetType();
943  if (m_evidence.ContainsKey(type))
944  {
945  GetHostEvidenceNoLock(type);
946  }
947  EvidenceBase evidence2 = WrapLegacyEvidence(hostEnumerator.Current);
948  AddHostEvidenceNoLock(evidence2, GetEvidenceIndexType(evidence2), DuplicateEvidenceAction.Merge);
949  }
950  IEnumerator assemblyEnumerator = evidence.GetAssemblyEnumerator();
951  while (assemblyEnumerator.MoveNext())
952  {
953  EvidenceBase evidence3 = WrapLegacyEvidence(assemblyEnumerator.Current);
954  AddAssemblyEvidenceNoLock(evidence3, GetEvidenceIndexType(evidence3), DuplicateEvidenceAction.Merge);
955  }
956  }
957  }
958  }
959 
960  internal void MergeWithNoDuplicates(Evidence evidence)
961  {
962  if (evidence != null)
963  {
964  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
965  {
966  IEnumerator hostEnumerator = evidence.GetHostEnumerator();
967  while (hostEnumerator.MoveNext())
968  {
969  EvidenceBase evidence2 = WrapLegacyEvidence(hostEnumerator.Current);
970  AddHostEvidenceNoLock(evidence2, GetEvidenceIndexType(evidence2), DuplicateEvidenceAction.SelectNewObject);
971  }
972  IEnumerator assemblyEnumerator = evidence.GetAssemblyEnumerator();
973  while (assemblyEnumerator.MoveNext())
974  {
975  EvidenceBase evidence3 = WrapLegacyEvidence(assemblyEnumerator.Current);
976  AddAssemblyEvidenceNoLock(evidence3, GetEvidenceIndexType(evidence3), DuplicateEvidenceAction.SelectNewObject);
977  }
978  }
979  }
980  }
981 
982  [ComVisible(false)]
983  [OnSerializing]
984  [SecurityCritical]
985  [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
986  private void OnSerializing(StreamingContext context)
987  {
988  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
989  {
990  foreach (Type item in new List<Type>(m_evidence.Keys))
991  {
992  GetHostEvidenceNoLock(item);
993  }
994  DeserializeTargetEvidence();
995  }
996  ArrayList arrayList = new ArrayList();
997  IEnumerator hostEnumerator = GetHostEnumerator();
998  while (hostEnumerator.MoveNext())
999  {
1000  arrayList.Add(hostEnumerator.Current);
1001  }
1002  m_hostList = arrayList;
1003  ArrayList arrayList2 = new ArrayList();
1004  IEnumerator assemblyEnumerator = GetAssemblyEnumerator();
1005  while (assemblyEnumerator.MoveNext())
1006  {
1007  arrayList2.Add(assemblyEnumerator.Current);
1008  }
1009  m_assemblyList = arrayList2;
1010  }
1011 
1012  [ComVisible(false)]
1013  [OnDeserialized]
1014  [SecurityCritical]
1015  private void OnDeserialized(StreamingContext context)
1016  {
1017  if (m_evidence == null)
1018  {
1019  m_evidence = new Dictionary<Type, EvidenceTypeDescriptor>();
1020  if (m_hostList != null)
1021  {
1022  foreach (object host in m_hostList)
1023  {
1024  if (host != null)
1025  {
1026  AddHost(host);
1027  }
1028  }
1029  m_hostList = null;
1030  }
1031  if (m_assemblyList != null)
1032  {
1033  foreach (object assembly in m_assemblyList)
1034  {
1035  if (assembly != null)
1036  {
1037  AddAssembly(assembly);
1038  }
1039  }
1040  m_assemblyList = null;
1041  }
1042  }
1043  m_evidenceLock = new ReaderWriterLock();
1044  }
1045 
1046  private void DeserializeTargetEvidence()
1047  {
1048  if (m_target != null && !m_deserializedTargetEvidence)
1049  {
1050  bool flag = false;
1051  LockCookie lockCookie = default(LockCookie);
1052  try
1053  {
1054  if (!IsWriterLockHeld)
1055  {
1056  lockCookie = UpgradeToWriterLock();
1057  flag = true;
1058  }
1059  m_deserializedTargetEvidence = true;
1060  foreach (EvidenceBase item in m_target.GetFactorySuppliedEvidence())
1061  {
1062  AddAssemblyEvidenceNoLock(item, GetEvidenceIndexType(item), DuplicateEvidenceAction.Throw);
1063  }
1064  }
1065  finally
1066  {
1067  if (flag)
1068  {
1069  DowngradeFromWriterLock(ref lockCookie);
1070  }
1071  }
1072  }
1073  }
1074 
1075  [SecurityCritical]
1076  internal byte[] RawSerialize()
1077  {
1078  try
1079  {
1080  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1081  {
1083  foreach (KeyValuePair<Type, EvidenceTypeDescriptor> item in m_evidence)
1084  {
1085  if (item.Value != null && item.Value.HostEvidence != null)
1086  {
1087  dictionary[item.Key] = item.Value.HostEvidence;
1088  }
1089  }
1090  using (MemoryStream memoryStream = new MemoryStream())
1091  {
1092  BinaryFormatter binaryFormatter = new BinaryFormatter();
1093  binaryFormatter.Serialize(memoryStream, dictionary);
1094  return memoryStream.ToArray();
1095  }
1096  }
1097  }
1098  catch (SecurityException)
1099  {
1100  return null;
1101  }
1102  }
1103 
1111  [Obsolete("Evidence should not be treated as an ICollection. Please use the GetHostEnumerator and GetAssemblyEnumerator methods rather than using CopyTo.")]
1112  public void CopyTo(Array array, int index)
1113  {
1114  if (array == null)
1115  {
1116  throw new ArgumentNullException("array");
1117  }
1118  if (index < 0 || index > array.Length - Count)
1119  {
1120  throw new ArgumentOutOfRangeException("index");
1121  }
1122  int num = index;
1123  IEnumerator hostEnumerator = GetHostEnumerator();
1124  while (hostEnumerator.MoveNext())
1125  {
1126  array.SetValue(hostEnumerator.Current, num);
1127  num++;
1128  }
1129  IEnumerator assemblyEnumerator = GetAssemblyEnumerator();
1130  while (assemblyEnumerator.MoveNext())
1131  {
1132  array.SetValue(assemblyEnumerator.Current, num);
1133  num++;
1134  }
1135  }
1136 
1140  {
1141  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1142  {
1143  return new EvidenceEnumerator(this, EvidenceEnumerator.Category.Host);
1144  }
1145  }
1146 
1150  {
1151  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1152  {
1153  DeserializeTargetEvidence();
1154  return new EvidenceEnumerator(this, EvidenceEnumerator.Category.Assembly);
1155  }
1156  }
1157 
1158  internal RawEvidenceEnumerator GetRawAssemblyEvidenceEnumerator()
1159  {
1160  DeserializeTargetEvidence();
1161  return new RawEvidenceEnumerator(this, new List<Type>(m_evidence.Keys), hostEnumerator: false);
1162  }
1163 
1164  internal RawEvidenceEnumerator GetRawHostEvidenceEnumerator()
1165  {
1166  return new RawEvidenceEnumerator(this, new List<Type>(m_evidence.Keys), hostEnumerator: true);
1167  }
1168 
1171  [Obsolete("GetEnumerator is obsolete. Please use GetAssemblyEnumerator and GetHostEnumerator instead.")]
1173  {
1174  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1175  {
1176  return new EvidenceEnumerator(this, EvidenceEnumerator.Category.Host | EvidenceEnumerator.Category.Assembly);
1177  }
1178  }
1179 
1183  [ComVisible(false)]
1185  {
1186  return UnwrapEvidence(GetAssemblyEvidence(typeof(T))) as T;
1187  }
1188 
1189  internal EvidenceBase GetAssemblyEvidence(Type type)
1190  {
1191  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1192  {
1193  return GetAssemblyEvidenceNoLock(type);
1194  }
1195  }
1196 
1197  private EvidenceBase GetAssemblyEvidenceNoLock(Type type)
1198  {
1199  DeserializeTargetEvidence();
1200  return GetEvidenceTypeDescriptor(type)?.AssemblyEvidence;
1201  }
1202 
1206  [ComVisible(false)]
1207  public T GetHostEvidence<T>() where T : EvidenceBase
1208  {
1209  return UnwrapEvidence(GetHostEvidence(typeof(T))) as T;
1210  }
1211 
1212  internal T GetDelayEvaluatedHostEvidence<T>() where T : EvidenceBase, IDelayEvaluatedEvidence
1213  {
1214  return UnwrapEvidence(GetHostEvidence(typeof(T), markDelayEvaluatedEvidenceUsed: false)) as T;
1215  }
1216 
1217  internal EvidenceBase GetHostEvidence(Type type)
1218  {
1219  return GetHostEvidence(type, markDelayEvaluatedEvidenceUsed: true);
1220  }
1221 
1222  [SecuritySafeCritical]
1223  private EvidenceBase GetHostEvidence(Type type, bool markDelayEvaluatedEvidenceUsed)
1224  {
1225  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1226  {
1227  EvidenceBase hostEvidenceNoLock = GetHostEvidenceNoLock(type);
1228  if (markDelayEvaluatedEvidenceUsed)
1229  {
1230  (hostEvidenceNoLock as IDelayEvaluatedEvidence)?.MarkUsed();
1231  }
1232  return hostEvidenceNoLock;
1233  }
1234  }
1235 
1236  [SecurityCritical]
1237  private EvidenceBase GetHostEvidenceNoLock(Type type)
1238  {
1239  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(type);
1240  if (evidenceTypeDescriptor == null)
1241  {
1242  return null;
1243  }
1244  if (evidenceTypeDescriptor.HostEvidence != null)
1245  {
1246  return evidenceTypeDescriptor.HostEvidence;
1247  }
1248  if (m_target != null && !evidenceTypeDescriptor.Generated)
1249  {
1250  using (new EvidenceUpgradeLockHolder(this))
1251  {
1252  evidenceTypeDescriptor.Generated = true;
1253  EvidenceBase evidenceBase = GenerateHostEvidence(type, evidenceTypeDescriptor.HostCanGenerate);
1254  if (evidenceBase != null)
1255  {
1256  evidenceTypeDescriptor.HostEvidence = evidenceBase;
1257  Evidence evidence = (m_cloneOrigin != null) ? (m_cloneOrigin.Target as Evidence) : null;
1258  if (evidence != null)
1259  {
1260  using (new EvidenceLockHolder(evidence, EvidenceLockHolder.LockType.Writer))
1261  {
1262  EvidenceTypeDescriptor evidenceTypeDescriptor2 = evidence.GetEvidenceTypeDescriptor(type);
1263  if (evidenceTypeDescriptor2 != null && evidenceTypeDescriptor2.HostEvidence == null)
1264  {
1265  evidenceTypeDescriptor2.HostEvidence = evidenceBase.Clone();
1266  }
1267  }
1268  }
1269  }
1270  return evidenceBase;
1271  }
1272  }
1273  return null;
1274  }
1275 
1276  [SecurityCritical]
1277  private EvidenceBase GenerateHostEvidence(Type type, bool hostCanGenerate)
1278  {
1279  if (hostCanGenerate)
1280  {
1281  AppDomain appDomain = m_target.Target as AppDomain;
1282  Assembly assembly = m_target.Target as Assembly;
1283  EvidenceBase evidenceBase = null;
1284  if (appDomain != null)
1285  {
1286  evidenceBase = AppDomain.CurrentDomain.HostSecurityManager.GenerateAppDomainEvidence(type);
1287  }
1288  else if (assembly != null)
1289  {
1290  evidenceBase = AppDomain.CurrentDomain.HostSecurityManager.GenerateAssemblyEvidence(type, assembly);
1291  }
1292  if (evidenceBase != null)
1293  {
1294  if (!type.IsAssignableFrom(evidenceBase.GetType()))
1295  {
1296  string fullName = AppDomain.CurrentDomain.HostSecurityManager.GetType().FullName;
1297  string fullName2 = evidenceBase.GetType().FullName;
1298  string fullName3 = type.FullName;
1299  throw new InvalidOperationException(Environment.GetResourceString("Policy_IncorrectHostEvidence", fullName, fullName2, fullName3));
1300  }
1301  return evidenceBase;
1302  }
1303  }
1304  return m_target.GenerateEvidence(type);
1305  }
1306 
1309  [ComVisible(false)]
1310  public Evidence Clone()
1311  {
1312  return new Evidence(this);
1313  }
1314 
1316  [ComVisible(false)]
1317  [SecuritySafeCritical]
1318  public void Clear()
1319  {
1320  if (Locked)
1321  {
1322  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
1323  }
1324  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
1325  {
1326  m_version++;
1327  m_evidence.Clear();
1328  }
1329  }
1330 
1335  [ComVisible(false)]
1336  [SecuritySafeCritical]
1337  public void RemoveType(Type t)
1338  {
1339  if (t == null)
1340  {
1341  throw new ArgumentNullException("t");
1342  }
1343  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
1344  {
1345  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(t);
1346  if (evidenceTypeDescriptor != null)
1347  {
1348  m_version++;
1349  if (Locked && (evidenceTypeDescriptor.HostEvidence != null || evidenceTypeDescriptor.HostCanGenerate))
1350  {
1351  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
1352  }
1353  m_evidence.Remove(t);
1354  }
1355  }
1356  }
1357 
1358  internal void MarkAllEvidenceAsUsed()
1359  {
1360  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1361  {
1362  foreach (KeyValuePair<Type, EvidenceTypeDescriptor> item in m_evidence)
1363  {
1364  if (item.Value != null)
1365  {
1366  (item.Value.HostEvidence as IDelayEvaluatedEvidence)?.MarkUsed();
1367  (item.Value.AssemblyEvidence as IDelayEvaluatedEvidence)?.MarkUsed();
1368  }
1369  }
1370  }
1371  }
1372 
1373  private bool WasStrongNameEvidenceUsed()
1374  {
1375  using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
1376  {
1377  EvidenceTypeDescriptor evidenceTypeDescriptor = GetEvidenceTypeDescriptor(typeof(StrongName));
1378  if (evidenceTypeDescriptor != null)
1379  {
1380  return (evidenceTypeDescriptor.HostEvidence as IDelayEvaluatedEvidence)?.WasUsed ?? false;
1381  }
1382  return false;
1383  }
1384  }
1385  }
1386 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Encapsulates security decisions about an application. This class cannot be inherited.
Describes a set of security permissions applied to code. This class cannot be inherited.
void ReleaseWriterLock()
Decrements the lock count on the writer lock.
bool MoveNext()
Advances the enumerator to the next element of the collection.
Provides the Authenticode X.509v3 digital signature of a code assembly as evidence for policy evaluat...
Definition: Publisher.cs:11
void ReleaseReaderLock()
Decrements the lock count.
Represents a simple last-in-first-out (LIFO) non-generic collection of objects.
Definition: Stack.cs:13
Provides the strong name of a code assembly as evidence for policy evaluation. This class cannot be i...
Definition: StrongName.cs:12
int Count
Gets the number of evidence objects in the evidence set.
Definition: Evidence.cs:446
void AcquireReaderLock(int millisecondsTimeout)
Acquires a reader lock, using an T:System.Int32 value for the time-out.
Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be...
Definition: Zone.cs:10
void AddAssembly(object id)
Adds the specified assembly evidence to the evidence set.
Definition: Evidence.cs:686
Provides the application directory as evidence for policy evaluation. This class cannot be inherited.
Provides the Web site from which a code assembly originates as evidence for policy evaluation....
Definition: Site.cs:11
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
void Serialize(Stream serializationStream, object graph)
Serializes the object, or graph of objects with the specified top (root), to the given stream.
Definition: __Canon.cs:3
Specifies the current position within a stream.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
HostSecurityManagerOptions
Specifies the security policy components to be used by the host security manager.
Evidence(Evidence evidence)
Initializes a new instance of the T:System.Security.Policy.Evidence class from a shallow copy of an e...
Definition: Evidence.cs:514
Evidence Clone()
Returns a duplicate copy of this evidence object.
Definition: Evidence.cs:1310
Provides the URL from which a code assembly originates as evidence for policy evaluation....
Definition: Url.cs:10
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Provides a base class from which all objects to be used as evidence must derive.
Definition: EvidenceBase.cs:12
Evidence()
Initializes a new empty instance of the T:System.Security.Policy.Evidence class.
Definition: Evidence.cs:505
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Definition: AppDomain.cs:274
Represents an application domain, which is an isolated environment where applications execute....
Definition: AppDomain.cs:33
Defines a lock that supports single writers and multiple readers.
bool ContainsKey(TKey key)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains the specified key.
Definition: Dictionary.cs:1303
Serializes and deserializes an object, or an entire graph of connected objects, in binary format.
void AddAssemblyEvidence< T >(T evidence)
Adds an evidence object of the specified type to the assembly-supplied evidence list.
Definition: Evidence.cs:710
Represents a weak reference, which references an object while still allowing that object to be reclai...
The P:System.Uri.Host data.
Defines a key/value pair that can be set or retrieved.
Definition: KeyValuePair.cs:10
void AddHostEvidence< T >(T evidence)
Adds host evidence of the specified type to the host evidence collection.
Definition: Evidence.cs:754
SecurityAction
Specifies the security actions that can be performed using declarative security.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
T GetAssemblyEvidence< T >()
Gets assembly evidence of the specified type from the collection.
Definition: Evidence.cs:1184
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
IEnumerator GetAssemblyEnumerator()
Enumerates evidence provided by the assembly.
Definition: Evidence.cs:1149
virtual object Peek()
Returns the object at the top of the T:System.Collections.Stack without removing it.
Definition: Stack.cs:401
KeyCollection Keys
Gets a collection containing the keys in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:902
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Definition: MemoryStream.cs:13
LockCookie UpgradeToWriterLock(int millisecondsTimeout)
Upgrades a reader lock to the writer lock, using an Int32 value for the time-out.
virtual byte [] ToArray()
Writes the stream contents to a byte array, regardless of the P:System.IO.MemoryStream....
void CopyTo(Array array, int index)
Copies evidence objects to an T:System.Array.
Definition: Evidence.cs:1112
Provides evidence about the hash value for an assembly. This class cannot be inherited.
Definition: Hash.cs:13
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
bool IsSynchronized
Gets a value indicating whether the evidence set is thread-safe.
Definition: Evidence.cs:498
void AcquireWriterLock(int millisecondsTimeout)
Acquires the writer lock, using an T:System.Int32 value for the time-out.
bool Locked
Gets or sets a value indicating whether the evidence is locked.
Definition: Evidence.cs:405
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
virtual object Pop()
Removes and returns the object at the top of the T:System.Collections.Stack.
Definition: Stack.cs:413
Evidence(EvidenceBase[] hostEvidence, EvidenceBase[] assemblyEvidence)
Initializes a new instance of the T:System.Security.Policy.Evidence class from multiple sets of host ...
Definition: Evidence.cs:569
void Clear()
Removes the host and assembly evidence from the evidence set.
Definition: Evidence.cs:1318
Provides data for manifest-based activation of an application. This class cannot be inherited.
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
Definition: Dictionary.cs:17
bool IsWriterLockHeld
Gets a value indicating whether the current thread holds the writer lock.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
void RemoveType(Type t)
Removes the evidence for a given type from the host and assembly enumerations.
Definition: Evidence.cs:1337
object SyncRoot
Gets the synchronization root.
Definition: Evidence.cs:494
bool IsReaderLockHeld
Gets a value indicating whether the current thread holds a reader lock.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition: List.cs:14
bool IsReadOnly
Gets a value indicating whether the evidence set is read-only.
Definition: Evidence.cs:502
void Merge(Evidence evidence)
Merges the specified evidence set into the current evidence set.
Definition: Evidence.cs:927
void DowngradeFromWriterLock(ref LockCookie lockCookie)
Restores the lock status of the thread to what it was before M:System.Threading.ReaderWriterLock....
IEnumerator GetHostEnumerator()
Enumerates evidence supplied by the host.
Definition: Evidence.cs:1139
Defines the set of information that constitutes input to security policy decisions....
Definition: Evidence.cs:17
Confirms that a code assembly originates in the global assembly cache (GAC) as evidence for policy ev...
Definition: GacInstalled.cs:9
Specifies that the class can be serialized.
virtual int Count
Gets the number of elements contained in the T:System.Collections.Stack.
Definition: Stack.cs:236
The exception that is thrown when a method call is invalid for the object's current state.
virtual void Push(object obj)
Inserts an object at the top of the T:System.Collections.Stack.
Definition: Stack.cs:427
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
SecurityPermissionFlag
Specifies access flags for the security permission object.
Evidence(object[] hostEvidence, object[] assemblyEvidence)
Initializes a new instance of the T:System.Security.Policy.Evidence class from multiple sets of host ...
Definition: Evidence.cs:546
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Definition: Dictionary.cs:1624
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
void AddHost(object id)
Adds the specified evidence supplied by the host to the evidence set.
Definition: Evidence.cs:660
Defines evidence that represents permission requests. This class cannot be inherited.
IEnumerator GetEnumerator()
Enumerates all evidence in the set, both that provided by the host and that provided by the assembly.
Definition: Evidence.cs:1172
T GetHostEvidence< T >()
Gets host evidence of the specified type from the collection.
Definition: Evidence.cs:1207
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14