Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / EntityModel / SchemaObjectModel / FacetDescriptionElement.cs
1 //---------------------------------------------------------------------
2 // <copyright file="FacetDescriptionElement.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 using System;
10 using System.Collections.Generic;
11 using System.Text;
12 using System.Data.Metadata.Edm;
13 using System.Xml;
14 using System.Diagnostics;
15
16 namespace System.Data.EntityModel.SchemaObjectModel
17 {
18     internal abstract class FacetDescriptionElement : SchemaElement
19     {
20         int? _minValue;
21         int? _maxValue;
22         object _defaultValue;
23         bool _isConstant;
24
25         // won't be populated till you call CreateAndValidate
26         FacetDescription _facetDescription;
27
28         public FacetDescriptionElement(TypeElement type, string name)
29         : base(type, name)
30         {
31         }
32
33         protected override bool ProhibitAttribute(string namespaceUri, string localName)
34         {
35             if (base.ProhibitAttribute(namespaceUri, localName))
36             {
37                 return true;
38             }
39
40             if (namespaceUri == null && localName == XmlConstants.Name)
41             {
42                 return false;
43             }
44             return false;
45
46         }
47
48         protected override bool HandleAttribute(XmlReader reader)
49         {
50             if (base.HandleAttribute(reader))
51             {
52                 return true;
53             }
54             else if (CanHandleAttribute(reader,  XmlConstants.MinimumAttribute))
55             {
56                 HandleMinimumAttribute(reader);
57                 return true;
58             }
59             else if (CanHandleAttribute(reader, XmlConstants.MaximumAttribute))
60             {
61                 HandleMaximumAttribute(reader);
62                 return true;
63             }
64             else if (CanHandleAttribute(reader, XmlConstants.DefaultValueAttribute))
65             {
66                 HandleDefaultAttribute(reader);
67                 return true;
68             }
69             else if (CanHandleAttribute(reader, XmlConstants.ConstantAttribute))
70             {
71                 HandleConstantAttribute(reader);
72                 return true;
73             }
74
75             return false;
76         }
77
78         /////////////////////////////////////////////////////////////////////
79         // Attribute Handlers
80
81         /// <summary>
82         /// Handler for the Minimum attribute
83         /// </summary>
84         /// <param name="reader">xml reader currently positioned at Minimum attribute</param>
85         protected void HandleMinimumAttribute(XmlReader reader)
86         {
87             int value = -1;
88             if (HandleIntAttribute(reader, ref value))
89             {
90                 _minValue = value;
91             }
92         }
93
94         /// <summary>
95         /// Handler for the Maximum attribute
96         /// </summary>
97         /// <param name="reader">xml reader currently positioned at Maximum attribute</param>
98         protected void HandleMaximumAttribute(XmlReader reader)
99         {
100             int value = -1;
101             if (HandleIntAttribute(reader, ref value))
102             {
103                 _maxValue = value;
104             }
105         }
106
107         /// <summary>
108         /// Handler for the Default attribute
109         /// </summary>
110         /// <param name="reader">xml reader currently positioned at Default attribute</param>
111         protected abstract void HandleDefaultAttribute(XmlReader reader);
112
113         /// <summary>
114         /// Handler for the Constant attribute
115         /// </summary>
116         /// <param name="reader">xml reader currently positioned at Constant attribute</param>
117         protected void HandleConstantAttribute(XmlReader reader)
118         {
119             bool value = false;
120             if (HandleBoolAttribute(reader, ref value))
121             {
122                 _isConstant = value;
123             }
124         }
125
126         public abstract EdmType FacetType{ get; }
127         
128         public int? MinValue
129         {
130             get { return _minValue; }
131         }
132         
133         public int? MaxValue
134         {
135             get { return _maxValue; }
136         }
137         
138         public object DefaultValue
139         {
140             get { return _defaultValue; }
141             set { _defaultValue = value; }
142         }
143
144         public FacetDescription FacetDescription
145         {
146             get
147             {
148                 Debug.Assert(_facetDescription != null, "Did you forget to call CreateAndValidate first?");
149                 return _facetDescription;
150             }
151         }
152
153         internal void CreateAndValidateFacetDescription(string declaringTypeName)
154         {
155             _facetDescription = new FacetDescription(Name, FacetType, MinValue, MaxValue, DefaultValue, _isConstant, declaringTypeName);
156         }
157     }
158 }