Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / System / Data / Sql / SqlUserDefinedTypeAttribute.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SqlUserDefinedTypeAttribute.cs" company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation. All Rights Reserved.
4 //     Information Contained Herein is Proprietary and Confidential.
5 //  </copyright>
6 // <owner current="true" primary="true">Microsoft</owner>
7 // <owner current="true" primary="true">Microsoft</owner>
8 // <owner current="true" primary="true">daltudov</owner>
9 // <owner current="true" primary="true">Microsoft</owner>
10 // <owner current="true" primary="false">beysims</owner>
11 // <owner current="true" primary="false">Microsoft</owner>
12 // <owner current="true" primary="false">vadimt</owner>
13 // <owner current="false" primary="false">venkar</owner>
14 // <owner current="false" primary="false">Microsoft</owner>
15 //------------------------------------------------------------------------------
16
17 namespace Microsoft.SqlServer.Server {
18
19     using System; 
20     using System.Data.Common;
21
22     public enum Format { //: byte
23         Unknown                    = 0,
24         Native                     = 1,
25         UserDefined                = 2,
26     }
27
28     // This custom attribute indicates that the given type is
29     // a SqlServer udt. The properties on the attribute reflect the
30     // physical attributes that will be used when the type is registered
31     // with SqlServer.
32     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple=false, Inherited=true)]
33     public sealed class SqlUserDefinedTypeAttribute: Attribute {
34         private int m_MaxByteSize;
35         private bool m_IsFixedLength;
36         private bool m_IsByteOrdered;
37         private Format m_format;
38         private string m_fName;
39         
40         // The maximum value for the maxbytesize field, in bytes.
41         internal const int YukonMaxByteSizeValue = 8000;
42         private String m_ValidationMethodName = null;
43
44
45         // A required attribute on all udts, used to indicate that the
46         // given type is a udt, and its storage format.
47         public SqlUserDefinedTypeAttribute(Format format) {
48             switch(format) {
49             case Format.Unknown:
50                 throw ADP.NotSupportedUserDefinedTypeSerializationFormat((Microsoft.SqlServer.Server.Format)format, "format");
51             case Format.Native:
52             case Format.UserDefined:
53                 this.m_format = format;
54                 break;
55             default:
56                 throw ADP.InvalidUserDefinedTypeSerializationFormat((Microsoft.SqlServer.Server.Format)format);
57             }
58         }
59
60         // The maximum size of this instance, in bytes. Does not have to be
61         // specified for Native serialization. The maximum value
62         // for this property is specified by MaxByteSizeValue.
63         public int MaxByteSize {
64             get {
65                 return this.m_MaxByteSize;
66             }
67             set {
68                 if (value < -1) {
69                     throw ADP.ArgumentOutOfRange("MaxByteSize");
70                 }
71                 this.m_MaxByteSize = value;
72             }
73         }
74
75         // Are all instances of this udt the same size on disk?
76         public bool IsFixedLength {
77             get {
78                 return this.m_IsFixedLength;
79             }
80             set {
81                 this.m_IsFixedLength = value;
82             }
83         }
84
85         // Is this type byte ordered, i.e. is the on disk representation
86         // consistent with the ordering semantics for this type?
87         // If true, the binary representation of the type will be used
88         // in comparison by SqlServer. This property enables indexing on the
89         // udt and faster comparisons.
90         public bool IsByteOrdered {
91             get {
92                 return this.m_IsByteOrdered;
93             }
94             set {
95                 this.m_IsByteOrdered = value;
96             }
97         }
98
99         // The on-disk format for this type.
100         public Format Format {
101             get {
102                 return this.m_format;
103             }
104         }
105
106         // An Optional method used to validate this UDT
107         // Signature: bool &lt;ValidationMethodName&gt;();
108         public String ValidationMethodName {
109             get
110             {
111                 return this.m_ValidationMethodName;
112             }
113             set
114             {
115                 this.m_ValidationMethodName = value;
116             }
117         }
118
119         public string Name {
120             get {
121                 return m_fName;
122             }
123             set {
124                 m_fName = value;
125             }
126         }
127     }
128 }