Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / Schema / SchemaDeclBase.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SchemaDeclBase.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright> 
5 // <owner current="true" primary="true">[....]</owner>                                                               
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml.Schema {
9
10     using System.Collections.Generic;
11     using System.Diagnostics;
12
13     internal abstract class SchemaDeclBase {
14         internal enum Use {
15             Default,
16             Required,
17             Implied,
18             Fixed,
19             RequiredFixed
20         };
21
22         protected XmlQualifiedName  name = XmlQualifiedName.Empty;
23         protected string            prefix;
24         protected bool isDeclaredInExternal = false;
25         protected Use               presence;     // the presence, such as fixed, implied, etc
26
27 #if !SILVERLIGHT
28         protected XmlSchemaType     schemaType;
29         protected XmlSchemaDatatype datatype;
30
31         protected string            defaultValueRaw;       // default value in its original form
32         protected object            defaultValueTyped;       
33
34         protected long               maxLength; // dt:maxLength
35         protected long               minLength; // dt:minLength
36
37         protected List<string> values;    // array of values for enumerated and notation types
38 #endif
39
40         protected SchemaDeclBase(XmlQualifiedName name, string prefix) {
41             this.name = name;
42             this.prefix = prefix;
43 #if !SILVERLIGHT
44             maxLength = -1;
45             minLength = -1;
46 #endif
47         }
48
49 #if !SILVERLIGHT
50         protected SchemaDeclBase() {
51         }
52 #endif
53
54         internal XmlQualifiedName Name {
55             get { return name;}
56             set { name = value;}
57         }
58
59         internal string Prefix {
60             get { return(prefix == null) ? string.Empty : prefix;}
61             set { prefix = value;}
62         }
63
64         internal bool IsDeclaredInExternal {
65             get { return isDeclaredInExternal;}
66             set { isDeclaredInExternal = value;}
67         }
68
69         internal Use Presence {
70             get { return presence; }
71             set { presence = value; }
72         }
73
74 #if !SILVERLIGHT
75         internal long MaxLength {
76             get { return maxLength;}
77             set { maxLength = value;}
78         }
79
80         internal long MinLength {
81             get { return minLength;}
82             set { minLength = value;}
83         }
84
85         internal XmlSchemaType SchemaType {
86             get { return schemaType;}
87             set { schemaType = value;}
88         }
89
90         internal XmlSchemaDatatype Datatype {
91             get { return datatype;}
92             set { datatype = value;}
93         }
94
95         internal void AddValue(string value) {
96             if (values == null) {
97                 values = new List<string>();
98             }
99             values.Add(value);
100         }
101
102         internal List<string> Values {
103             get { return values; }
104             set { values = value; }
105         }
106
107         internal string DefaultValueRaw {
108             get { return(defaultValueRaw != null) ? defaultValueRaw : string.Empty;}
109             set { defaultValueRaw = value;}
110         }
111
112         internal object DefaultValueTyped {
113             get { return defaultValueTyped;}
114             set { defaultValueTyped = value;}
115         }
116
117         internal bool CheckEnumeration(object pVal) {
118             return (datatype.TokenizedType != XmlTokenizedType.NOTATION && datatype.TokenizedType != XmlTokenizedType.ENUMERATION) || values.Contains(pVal.ToString());
119         }
120
121         internal bool CheckValue(Object pVal) {
122             return (presence != Use.Fixed && presence != Use.RequiredFixed) || (defaultValueTyped != null && datatype.IsEqual(pVal, defaultValueTyped));
123         }
124 #endif
125     };
126
127 }