The Labs \ Source Viewer \ SSCLI \ System.Security.Policy \ GacMembershipCondition

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. //
  16. // GacMembershipCondition.cs
  17. //
  18. // Implementation of membership condition for being in the Gac
  19. //
  20. namespace System.Security.Policy
  21. {
  22.     using System;
  23.     using System.Collections;
  24.     using System.Globalization;
  25.    
  26.     [Serializable()]
  27.     [System.Runtime.InteropServices.ComVisible(true)]
  28.     public sealed class GacMembershipCondition : IMembershipCondition, IConstantMembershipCondition
  29.     {
  30.         //------------------------------------------------------
  31.         //
  32.         // PUBLIC CONSTRUCTORS
  33.         //
  34.         //------------------------------------------------------
  35.        
  36.         public GacMembershipCondition()
  37.         {
  38.         }
  39.        
  40.         //------------------------------------------------------
  41.         //
  42.         // IMEMBERSHIPCONDITION IMPLEMENTATION
  43.         //
  44.         //------------------------------------------------------
  45.        
  46.         public bool Check(Evidence evidence)
  47.         {
  48.             if (evidence == null)
  49.                 return false;
  50.            
  51.             IEnumerator enumerator = evidence.GetHostEnumerator();
  52.             while (enumerator.MoveNext()) {
  53.                 object obj = enumerator.Current;
  54.                 if (obj is GacInstalled)
  55.                     return true;
  56.             }
  57.             return false;
  58.         }
  59.        
  60.         public IMembershipCondition Copy()
  61.         {
  62.             return new GacMembershipCondition();
  63.         }
  64.        
  65.         public SecurityElement ToXml()
  66.         {
  67.             return ToXml(null);
  68.         }
  69.        
  70.         public void FromXml(SecurityElement e)
  71.         {
  72.             FromXml(e, null);
  73.         }
  74.        
  75.         public SecurityElement ToXml(PolicyLevel level)
  76.         {
  77.             SecurityElement root = new SecurityElement("IMembershipCondition");
  78.             System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType(), this.GetType().FullName);
  79.             root.AddAttribute("version", "1");
  80.             return root;
  81.         }
  82.        
  83.         public void FromXml(SecurityElement e, PolicyLevel level)
  84.         {
  85.             if (e == null)
  86.                 throw new ArgumentNullException("e");
  87.            
  88.             if (!e.Tag.Equals("IMembershipCondition"))
  89.                 throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"));
  90.         }
  91.        
  92.         public override bool Equals(object o)
  93.         {
  94.             GacMembershipCondition that = (o as GacMembershipCondition);
  95.             if (that != null)
  96.                 return true;
  97.             return false;
  98.         }
  99.        
  100.         public override int GetHashCode()
  101.         {
  102.             return 0;
  103.         }
  104.        
  105.         public override string ToString()
  106.         {
  107.             return Environment.GetResourceString("GAC_ToString");
  108.         }
  109.     }
  110. }

Developer Fusion