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

  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. // AllMembershipCondition.cs
  16. //
  17. // Simple IMembershipCondition implementation that always passes
  18. //
  19. namespace System.Security.Policy
  20. {
  21.    
  22.     using System;
  23.     using System.Security;
  24.     using System.Security.Util;
  25.     using System.Security.Permissions;
  26.     using System.Collections;
  27.    
  28.     [Serializable()]
  29.     [System.Runtime.InteropServices.ComVisible(true)]
  30.     public sealed class AllMembershipCondition : IMembershipCondition, IConstantMembershipCondition
  31.     {
  32.         public AllMembershipCondition()
  33.         {
  34.         }
  35.        
  36.         public bool Check(Evidence evidence)
  37.         {
  38.             return true;
  39.         }
  40.        
  41.         public IMembershipCondition Copy()
  42.         {
  43.             return new AllMembershipCondition();
  44.         }
  45.        
  46.         public override string ToString()
  47.         {
  48.             return Environment.GetResourceString("All_ToString");
  49.         }
  50.        
  51.         public SecurityElement ToXml()
  52.         {
  53.             return ToXml(null);
  54.         }
  55.        
  56.         public void FromXml(SecurityElement e)
  57.         {
  58.             FromXml(e, null);
  59.         }
  60.        
  61.         public SecurityElement ToXml(PolicyLevel level)
  62.         {
  63.             SecurityElement root = new SecurityElement("IMembershipCondition");
  64.             System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType(), "System.Security.Policy.AllMembershipCondition");
  65.             // If you hit this assert then most likely you are trying to change the name of this class.
  66.             // This is ok as long as you change the hard coded string above and change the assert below.
  67.             BCLDebug.Assert(this.GetType().FullName.Equals("System.Security.Policy.AllMembershipCondition"), "Class name changed!");
  68.            
  69.             root.AddAttribute("version", "1");
  70.            
  71.             return root;
  72.         }
  73.        
  74.         public void FromXml(SecurityElement e, PolicyLevel level)
  75.         {
  76.             if (e == null)
  77.                 throw new ArgumentNullException("e");
  78.            
  79.             if (!e.Tag.Equals("IMembershipCondition")) {
  80.                 throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"));
  81.             }
  82.            
  83.         }
  84.        
  85.         public override bool Equals(object o)
  86.         {
  87.             return (o is AllMembershipCondition);
  88.         }
  89.        
  90.         public override int GetHashCode()
  91.         {
  92.             return typeof(AllMembershipCondition).GetHashCode();
  93.         }
  94.     }
  95. }

Developer Fusion