DBDataPermissionAttribute.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //------------------------------------------------------------------------------
  2. // <copyright file="DBDataPermissionAttribute.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">Microsoft</owner>
  6. // <owner current="true" primary="false">Microsoft</owner>
  7. //------------------------------------------------------------------------------
  8. namespace System.Data.Common {
  9. using System.ComponentModel;
  10. using System.Data.Common;
  11. using System.Diagnostics;
  12. using System.Security;
  13. using System.Security.Permissions;
  14. /* derived class pattern
  15. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
  16. [Serializable] sealed public class XPermissionAttribute : DBDataPermissionAttribute {
  17. public XPermissionAttribute(SecurityAction action) : base(action) {
  18. }
  19. override public IPermission CreatePermission() {
  20. return new XPermission(this);
  21. }
  22. }
  23. */
  24. [Serializable(), AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
  25. public abstract class DBDataPermissionAttribute : CodeAccessSecurityAttribute { // V1.0.3300
  26. private bool _allowBlankPassword;// = false;
  27. private string _connectionString;// = ADP.StrEmpty;
  28. private string _restrictions;// = ADP.StrEmpty;
  29. private KeyRestrictionBehavior _behavior;// = KeyRestrictionBehavior.AllowOnly;
  30. protected DBDataPermissionAttribute(SecurityAction action) : base(action) {
  31. }
  32. public bool AllowBlankPassword { // V1.0.3300
  33. get {
  34. return _allowBlankPassword;
  35. }
  36. set {
  37. _allowBlankPassword = value;
  38. }
  39. }
  40. public string ConnectionString { // V1.0.5000
  41. get {
  42. string value = _connectionString;
  43. return ((null != value) ? value : String.Empty);
  44. }
  45. set {
  46. _connectionString = value;
  47. }
  48. }
  49. public KeyRestrictionBehavior KeyRestrictionBehavior { // V1.0.5000, default AllowOnly
  50. get {
  51. return _behavior;
  52. }
  53. set {
  54. switch(value) {
  55. case KeyRestrictionBehavior.PreventUsage:
  56. case KeyRestrictionBehavior.AllowOnly:
  57. _behavior = value;
  58. break;
  59. default:
  60. throw ADP.InvalidKeyRestrictionBehavior(value);
  61. }
  62. }
  63. }
  64. public string KeyRestrictions { // V1.0.5000
  65. get {
  66. string value = _restrictions;
  67. return (null != value) ? value : ADP.StrEmpty;
  68. }
  69. set {
  70. _restrictions = value;
  71. }
  72. }
  73. [ EditorBrowsableAttribute(EditorBrowsableState.Never) ]
  74. public bool ShouldSerializeConnectionString() { // V1.2.3300
  75. return (null != _connectionString);
  76. }
  77. [ EditorBrowsableAttribute(EditorBrowsableState.Never) ]
  78. public bool ShouldSerializeKeyRestrictions() { // V1.2.3300
  79. return (null != _restrictions);
  80. }
  81. }
  82. }