Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / System / Data / Common / DBDataPermissionAttribute.cs
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
9 namespace System.Data.Common {
10
11     using System.ComponentModel;
12     using System.Data.Common;
13     using System.Diagnostics;
14     using System.Security;
15     using System.Security.Permissions;
16
17     /* derived class pattern
18     [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
19     [Serializable] sealed public class XPermissionAttribute : DBDataPermissionAttribute {
20         public XPermissionAttribute(SecurityAction action) : base(action) {
21         }
22         override public IPermission CreatePermission() {
23             return new XPermission(this);
24         }
25     }
26     */
27
28     [Serializable(), AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
29     public abstract class DBDataPermissionAttribute : CodeAccessSecurityAttribute { // V1.0.3300
30         private bool _allowBlankPassword;// = false;
31         private string _connectionString;// = ADP.StrEmpty;
32         private string _restrictions;// = ADP.StrEmpty;
33         private KeyRestrictionBehavior _behavior;// = KeyRestrictionBehavior.AllowOnly;
34
35         protected DBDataPermissionAttribute(SecurityAction action) : base(action) {
36         }
37
38         public bool AllowBlankPassword { // V1.0.3300
39             get {
40                 return _allowBlankPassword;
41             }
42             set {
43                 _allowBlankPassword = value;
44             }
45         }
46
47         public string ConnectionString { // V1.0.5000
48             get {
49                 string value = _connectionString;
50                 return ((null != value) ? value : String.Empty);
51             }
52             set {
53                 _connectionString = value;
54             }
55         }
56
57         public KeyRestrictionBehavior KeyRestrictionBehavior { // V1.0.5000, default AllowOnly
58             get {
59                 return _behavior;
60             }
61             set {
62                 switch(value) {
63                 case KeyRestrictionBehavior.PreventUsage:
64                 case KeyRestrictionBehavior.AllowOnly:
65                     _behavior = value;
66                     break;
67                 default:
68                     throw ADP.InvalidKeyRestrictionBehavior(value);
69                 }
70             }
71         }
72
73         public string KeyRestrictions { // V1.0.5000
74             get {
75                 string value = _restrictions;
76                 return (null != value) ? value : ADP.StrEmpty;
77             }
78             set {
79                 _restrictions = value;
80             }
81         }
82
83         [ EditorBrowsableAttribute(EditorBrowsableState.Never) ]
84         public bool ShouldSerializeConnectionString() { // V1.2.3300
85             return (null != _connectionString);
86         }
87
88         [ EditorBrowsableAttribute(EditorBrowsableState.Never) ]
89         public bool ShouldSerializeKeyRestrictions() { // V1.2.3300
90             return (null != _restrictions);
91         }
92     }
93 }