예제 #1
0
        internal ClrTypeReference(string name, string ns, XmlSchemaObject schemaObject, bool anonymousType,
                                  bool setVariety)
        {
            this.typeName     = name;
            this.typeNs       = ns;
            this.schemaObject = schemaObject;

            XmlSchemaType schemaType = schemaObject as XmlSchemaType;

            if (schemaType == null)
            {
                XmlSchemaElement elem = schemaObject as XmlSchemaElement;
                typeRefFlags |= ClrTypeRefFlags.IsElementRef;
                schemaType    = elem.ElementSchemaType;
            }

            Debug.Assert(schemaType != null);

            XmlSchemaSimpleType st = schemaType as XmlSchemaSimpleType;

            if (st != null)
            {
                if (st.HasFacetRestrictions() || st.IsOrHasUnion())
                {
                    typeRefFlags |= ClrTypeRefFlags.Validate;
                }

                if (st.IsEnum())
                {
                    typeRefFlags |= ClrTypeRefFlags.IsEnum;
                }

                XmlSchemaDatatype datatype = st.Datatype;
                if (setVariety)
                {
                    SetVariety(datatype);
                }

                typeRefFlags  |= ClrTypeRefFlags.IsSimpleType;
                typeCodeString = datatype.TypeCodeString();
                if (datatype.ValueType.IsValueType)
                {
                    typeRefFlags |= ClrTypeRefFlags.IsValueType;
                }
            }
            else if (schemaType.TypeCode == XmlTypeCode.Item)
            {
                typeRefFlags |= ClrTypeRefFlags.IsAnyType;
            }

            if (anonymousType)
            {
                typeRefFlags |= ClrTypeRefFlags.IsLocalType;
            }

            this.typeRefOrigin = SchemaOrigin.Fragment;
        }