The Labs \ Source Viewer \ SSCLI \ System.Security.Permissions \ GacIdentityPermission

  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. // GacIdentityPermission.cs
  16. //
  17. namespace System.Security.Permissions
  18. {
  19.     using System;
  20.     using SecurityElement = System.Security.SecurityElement;
  21.     using System.Globalization;
  22.    
  23.     [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
  24.     [System.Runtime.InteropServices.ComVisible(true)]
  25.     [Serializable()]
  26.     public sealed class GacIdentityPermissionAttribute : CodeAccessSecurityAttribute
  27.     {
  28.         public GacIdentityPermissionAttribute(SecurityAction action) : base(action)
  29.         {
  30.         }
  31.        
  32.         public override IPermission CreatePermission()
  33.         {
  34.             return new GacIdentityPermission();
  35.         }
  36.     }
  37.    
  38.    
  39.     [System.Runtime.InteropServices.ComVisible(true)]
  40.     [Serializable()]
  41.     public sealed class GacIdentityPermission : CodeAccessPermission, IBuiltInPermission
  42.     {
  43.         //------------------------------------------------------
  44.         //
  45.         // PUBLIC CONSTRUCTORS
  46.         //
  47.         //------------------------------------------------------
  48.        
  49.         public GacIdentityPermission(PermissionState state)
  50.         {
  51.             if (state == PermissionState.Unrestricted) {
  52.                 if (!CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust())
  53.                     throw new ArgumentException(Environment.GetResourceString("Argument_UnrestrictedIdentityPermission"));
  54.             }
  55.             else if (state == PermissionState.None) {
  56.                
  57.             }
  58.             else {
  59.                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
  60.             }
  61.         }
  62.        
  63.         public GacIdentityPermission()
  64.         {
  65.         }
  66.        
  67.         //------------------------------------------------------
  68.         //
  69.         // IPERMISSION IMPLEMENTATION
  70.         //
  71.         //------------------------------------------------------
  72.        
  73.        
  74.         public override IPermission Copy()
  75.         {
  76.             return new GacIdentityPermission();
  77.         }
  78.        
  79.         public override bool IsSubsetOf(IPermission target)
  80.         {
  81.             if (target == null)
  82.                 return false;
  83.             if (!(target is GacIdentityPermission))
  84.                 throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName));
  85.             return true;
  86.         }
  87.        
  88.         public override IPermission Intersect(IPermission target)
  89.         {
  90.             if (target == null)
  91.                 return null;
  92.             if (!(target is GacIdentityPermission))
  93.                 throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName));
  94.             return this.Copy();
  95.         }
  96.        
  97.         public override IPermission Union(IPermission target)
  98.         {
  99.             if (target == null)
  100.                 return this.Copy();
  101.             if (!(target is GacIdentityPermission))
  102.                 throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName));
  103.             return this.Copy();
  104.         }
  105.        
  106.         public override SecurityElement ToXml()
  107.         {
  108.             SecurityElement securityElement = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.GacIdentityPermission");
  109.             return securityElement;
  110.         }
  111.        
  112.         public override void FromXml(SecurityElement securityElement)
  113.         {
  114.             CodeAccessPermission.ValidateElement(securityElement, this);
  115.         }
  116.        
  117.         /// <internalonly/>
  118.         int IBuiltInPermission.GetTokenIndex()
  119.         {
  120.             return GacIdentityPermission.GetTokenIndex();
  121.         }
  122.        
  123.         static internal int GetTokenIndex()
  124.         {
  125.             return BuiltInPermissionIndex.GacIdentityPermissionIndex;
  126.         }
  127.     }
  128. }

Developer Fusion