PrintingPermission.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // System.Drawing.PrintingPermission.cs
  3. //
  4. // Author:
  5. // Dennis Hayes ([email protected])
  6. // Herve Poussineau ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc
  9. //
  10. using System;
  11. using System.Security;
  12. using System.Security.Permissions;
  13. namespace System.Drawing.Printing
  14. {
  15. /// <summary>
  16. /// Summary description for PrintingPermission.
  17. /// </summary>
  18. ///
  19. [Serializable]
  20. public sealed class PrintingPermission : CodeAccessPermission, IUnrestrictedPermission
  21. {
  22. private PrintingPermissionLevel _Level;
  23. public PrintingPermission(PermissionState state) {
  24. switch (state)
  25. {
  26. case PermissionState.None:
  27. Level = PrintingPermissionLevel.NoPrinting;
  28. break;
  29. case PermissionState.Unrestricted:
  30. Level = PrintingPermissionLevel.AllPrinting;
  31. break;
  32. default:
  33. // should never happen
  34. throw new ArgumentException("state");
  35. }
  36. }
  37. public PrintingPermission(PrintingPermissionLevel printingLevel) {
  38. Level = printingLevel;
  39. }
  40. // properties
  41. public PrintingPermissionLevel Level{
  42. get{
  43. return _Level;
  44. }
  45. set{
  46. _Level = value;
  47. }
  48. }
  49. // methods
  50. public override IPermission Copy(){
  51. return new PrintingPermission(this.Level);
  52. }
  53. [MonoTODO("PrintingPermission.FromXml")]
  54. public override void FromXml(SecurityElement esd)
  55. {
  56. throw new NotImplementedException();
  57. }
  58. public override IPermission Intersect(IPermission target)
  59. {
  60. if (this.IsSubsetOf(target))
  61. return this.Copy();
  62. else
  63. return target.Copy();
  64. }
  65. public override bool IsSubsetOf(IPermission target)
  66. {
  67. if (!(target is PrintingPermission))
  68. throw new ArgumentException("target");
  69. return this.Level <= (target as PrintingPermission).Level;
  70. }
  71. public bool IsUnrestricted()
  72. {
  73. return (this.Level == PrintingPermissionLevel.AllPrinting);
  74. }
  75. [MonoTODO("PrintingPermission.ToXml")]
  76. public override SecurityElement ToXml()
  77. {
  78. throw new NotImplementedException();
  79. }
  80. public override IPermission Union(IPermission target)
  81. {
  82. if (this.IsSubsetOf(target))
  83. return target.Copy();
  84. else
  85. return this.Copy();
  86. }
  87. }
  88. }