1 //------------------------------------------------------------------------------
2 // <copyright file="XmlSchemaInfo.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7 
8 using System.Xml;
9 using System.Collections;
10 
11 namespace System.Xml.Schema {
12 
13     /// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo"]/*' />
14     public class XmlSchemaInfo : IXmlSchemaInfo {
15         bool isDefault;
16         bool isNil;
17         XmlSchemaElement schemaElement;
18         XmlSchemaAttribute schemaAttribute;
19         XmlSchemaType schemaType;
20         XmlSchemaSimpleType memberType;
21         XmlSchemaValidity validity;
22         XmlSchemaContentType contentType;
23 
XmlSchemaInfo()24         public XmlSchemaInfo() {
25             Clear();
26         }
27 
XmlSchemaInfo(XmlSchemaValidity validity)28         internal XmlSchemaInfo(XmlSchemaValidity validity) : this() {
29             this.validity = validity;
30         }
31 
32         public XmlSchemaValidity Validity {
33             get {
34                 return validity;
35             }
36             set {
37                 validity = value;
38             }
39         }
40 
41         public bool IsDefault {
42             get {
43                 return isDefault;
44             }
45             set {
46                 isDefault = value;
47             }
48         }
49 
50         public bool IsNil {
51             get {
52                 return isNil;
53             }
54             set {
55                 isNil = value;
56             }
57         }
58 
59         public XmlSchemaSimpleType MemberType {
60             get {
61                 return memberType;
62             }
63             set {
64                 memberType = value;
65             }
66         }
67 
68         public XmlSchemaType SchemaType {
69             get {
70                 return schemaType;
71             }
72             set {
73                 schemaType = value;
74                 if (schemaType != null) { //Member type will not change its content type
75                     contentType = schemaType.SchemaContentType;
76                 }
77                 else {
78                     contentType = XmlSchemaContentType.Empty;
79                 }
80             }
81         }
82 
83         public XmlSchemaElement SchemaElement {
84             get {
85                 return schemaElement;
86             }
87             set {
88                 schemaElement = value;
89                 if (value != null) { //Setting non-null SchemaElement means SchemaAttribute should be null
90                     schemaAttribute = null;
91                 }
92             }
93         }
94 
95         public XmlSchemaAttribute SchemaAttribute {
96             get {
97                 return schemaAttribute;
98             }
99             set {
100                 schemaAttribute = value;
101                 if (value != null) { //Setting non-null SchemaAttribute means SchemaElement should be null
102                     schemaElement = null;
103                 }
104             }
105         }
106 
107         public XmlSchemaContentType ContentType {
108             get {
109                 return contentType;
110             }
111             set {
112                 contentType = value;
113             }
114         }
115 
116         internal XmlSchemaType XmlType {
117             get {
118                 if (memberType != null) {
119                     return memberType;
120                 }
121                 return schemaType;
122             }
123         }
124 
125         internal bool HasDefaultValue {
126             get {
127                 return schemaElement != null && schemaElement.ElementDecl.DefaultValueTyped != null;
128             }
129         }
130 
131         internal bool IsUnionType {
132             get {
133                 if (schemaType == null || schemaType.Datatype == null) {
134                     return false;
135                 }
136                 return schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Union;
137             }
138         }
139 
Clear()140         internal void Clear() {
141             isNil = false;
142             isDefault = false;
143             schemaType = null;
144             schemaElement = null;
145             schemaAttribute = null;
146             memberType = null;
147             validity = XmlSchemaValidity.NotKnown;
148             contentType = XmlSchemaContentType.Empty;
149         }
150     }
151 }
152