DbDataPermissionAttribute.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // System.Data.Common.DbDataPermissionAttribute.cs
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. // Sebastien Pouliot <[email protected]>
  8. //
  9. // (C) Ximian, Inc
  10. // Copyright (C) Tim Coleman, 2002
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.ComponentModel;
  33. using System.Security.Permissions;
  34. using System.Globalization;
  35. namespace System.Data.Common {
  36. [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class |
  37. AttributeTargets.Struct | AttributeTargets.Constructor |
  38. AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
  39. [Serializable]
  40. public abstract class DBDataPermissionAttribute : CodeAccessSecurityAttribute {
  41. #region Fields
  42. bool allowBlankPassword;
  43. string keyRestrictions;
  44. #if NET_1_1
  45. KeyRestrictionBehavior keyRestrictionBehavior;
  46. string connectionString;
  47. #endif
  48. #endregion // Fields
  49. #region Constructors
  50. protected DBDataPermissionAttribute (SecurityAction action)
  51. : base (action)
  52. {
  53. }
  54. #endregion // Constructors
  55. #region Properties
  56. public bool AllowBlankPassword {
  57. get { return allowBlankPassword; }
  58. set { allowBlankPassword = value; }
  59. }
  60. public string KeyRestrictions {
  61. get {
  62. if (keyRestrictions == null)
  63. return String.Empty;
  64. return keyRestrictions;
  65. }
  66. set { keyRestrictions = value; }
  67. }
  68. #if NET_1_1
  69. public string ConnectionString {
  70. get {
  71. if (connectionString == null)
  72. return String.Empty;
  73. return connectionString;
  74. }
  75. set { connectionString = value; }
  76. }
  77. public KeyRestrictionBehavior KeyRestrictionBehavior {
  78. get { return keyRestrictionBehavior; }
  79. set {
  80. if (!Enum.IsDefined (typeof (KeyRestrictionBehavior), value)) {
  81. string msg = Locale.GetText ("Unknown value.");
  82. #if NET_2_0
  83. throw new ArgumentOutOfRangeException ("KeyRestrictionBehavior", value, msg);
  84. #else
  85. throw new ArgumentException ("KeyRestrictionBehavior", msg);
  86. #endif
  87. }
  88. keyRestrictionBehavior = value;
  89. }
  90. }
  91. #endif
  92. #endregion // Properties
  93. #region // Methods
  94. #if NET_2_0
  95. [MonoTODO ("configurable ? why is this in the attribute class ?")]
  96. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  97. public bool ShouldSerializeConnectionString ()
  98. {
  99. return false;
  100. }
  101. [MonoTODO ("configurable ? why is this in the attribute class ?")]
  102. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  103. public bool ShouldSerializeKeyRestrictions ()
  104. {
  105. return false;
  106. }
  107. #endif
  108. #endregion // Methods
  109. }
  110. }