private ClrPropertyInfo BuildProperty(XmlSchemaElement elem, bool fromBaseType)
        {
            string identifierName = localSymbolTable.AddLocalElement(elem);

            XmlSchemaType    schemaType     = elem.ElementSchemaType;
            XmlQualifiedName schemaTypeName = schemaType.QualifiedName;
            string           schemaName     = elem.QualifiedName.Name;
            string           schemaNs       = elem.QualifiedName.Namespace;
            string           clrNs          = elem.FormResolved() == XmlSchemaForm.Qualified
                ? configSettings.GetClrNamespace(schemaNs)
                : string.Empty;


            SchemaOrigin    typeRefOrigin = SchemaOrigin.Fragment;
            bool            isTypeRef     = false;
            bool            anonymousType = schemaTypeName.IsEmpty ? true : false;
            XmlSchemaObject schemaObject  = schemaType;

            ArrayList substitutionMembers = null;

            if (elem.IsGlobal())
            {
                substitutionMembers = IsSubstitutionGroupHead(elem);
                schemaTypeName      = elem.QualifiedName;
                isTypeRef           = true;
                typeRefOrigin       = SchemaOrigin.Element;
                schemaObject        =
                    schemas.GlobalElements
                    [schemaTypeName];     //For ref, get the element decl SOM object, as nameMappings are keyed off the SOM object
                anonymousType = false;
            }

            ClrTypeReference typeRef = BuildTypeReference(schemaObject, schemaTypeName, anonymousType, true);

            typeRef.Origin    = typeRefOrigin;
            typeRef.IsTypeRef = isTypeRef;
            if (anonymousType && !fromBaseType)
            {
                //to fixup later.
                localSymbolTable.AddAnonymousType(identifierName, elem, typeRef);
            }

            ClrPropertyInfo propertyInfo =
                new ClrPropertyInfo(identifierName, schemaNs, schemaName, GetOccurence(elem));

            propertyInfo.Origin        = SchemaOrigin.Element;
            propertyInfo.FromBaseType  = fromBaseType;
            propertyInfo.TypeReference = typeRef;

            //SetFixedDefaultValue(elem, propertyInfo);

            if (substitutionMembers != null)
            {
                propertyInfo.SubstitutionMembers = substitutionMembers;
            }

            //BuildAnnotationInformation(propertyInfo, elem);
            return(propertyInfo);
            //Place it in the element's namespace, maybe element's parent type's namespace?
        }
Beispiel #2
0
        internal void CreateTypeDeclaration(ClrTypeInfo clrTypeInfo)
        {
            this.clrTypeInfo = clrTypeInfo;
            this.SetElementWildCardFlag(clrTypeInfo.HasElementWildCard);
            string              schemaName  = clrTypeInfo.schemaName;
            string              schemaNs    = clrTypeInfo.schemaNs;
            string              clrTypeName = clrTypeInfo.clrtypeName;
            SchemaOrigin        typeOrigin  = clrTypeInfo.typeOrigin;
            CodeTypeDeclaration typeDecl    = CodeDomHelper.CreateTypeDeclaration(clrTypeName, this.InnerType);

            if (clrTypeInfo.IsAbstract)
            {
                CodeTypeDeclaration typeAttributes = typeDecl;
                typeAttributes.TypeAttributes = typeAttributes.TypeAttributes | TypeAttributes.Abstract;
            }
            else if (clrTypeInfo.IsSealed)
            {
                CodeTypeDeclaration codeTypeDeclaration = typeDecl;
                codeTypeDeclaration.TypeAttributes = codeTypeDeclaration.TypeAttributes | TypeAttributes.Sealed;
            }
            this.decl = typeDecl;
            this.AddBaseType();
            this.CreateServicesMembers();
            this.CreateDefaultConstructor(clrTypeInfo.Annotations);
        }
        private void SetUnionCatchAll(object value,
                                      string propertyName,
                                      XTypedElement container,
                                      XName itemXName,
                                      SimpleTypeValidator typeDef,
                                      SchemaOrigin origin)
        {
            UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator;

            Debug.Assert(unionDef != null);
            SimpleTypeValidator matchingType = null;
            object    typedValue;
            Exception e = unionDef.TryParseValue(value,
                                                 XTypedServices.NameTable,
                                                 new XNamespaceResolver(container.GetUntyped()),
                                                 out matchingType,
                                                 out typedValue);

            if (e != null)
            {
                throw new LinqToXsdException(propertyName, e.Message);
            }
            else
            {
                if (matchingType is ListSimpleTypeValidator)
                {
                    ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator;
                    switch (origin)
                    {
                    case SchemaOrigin.Element:
                        SetListElement(itemXName, value, listType.ItemType.DataType);
                        break;

                    case SchemaOrigin.Text:
                        SetListValue(value, listType.ItemType.DataType);
                        break;

                    case SchemaOrigin.Attribute:
                        SetListAttribute(itemXName, value, listType.ItemType.DataType);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (origin)
                    {
                    case SchemaOrigin.Element: SetElement(itemXName, value, matchingType.DataType); break;

                    case SchemaOrigin.Text: SetValue(value, matchingType.DataType); break;

                    case SchemaOrigin.Attribute: SetAttribute(itemXName, value, matchingType.DataType); break;

                    default: break;
                    }
                }
            }
        }
        public static CodeMemberProperty CreateTypeOriginProperty(SchemaOrigin typeOrigin)
        {
            CodeTypeReference  originType = new CodeTypeReference("SchemaOrigin");
            CodeMemberProperty property   = CodeDomHelper.CreateInterfaceImplProperty("TypeOrigin", "IXMetaData", originType);

            property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(originType), (typeOrigin == SchemaOrigin.Element ? "Element" : "Fragment"))));
            return(property);
        }
Beispiel #5
0
        public static CodeMemberProperty CreateTypeOriginProperty(SchemaOrigin typeOrigin)
        {
            CodeTypeReference  originType = new CodeTypeReference(Constants.Origin);
            CodeMemberProperty property   = CreateInterfaceImplProperty(Constants.TypeOrigin, Constants.IXMetaData, originType);

            property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(originType), typeOrigin == SchemaOrigin.Element ? "Element" : "Fragment")));
            return(property);
        }
        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;
        }
 private void Init()
 {
     this.clrtypeName  = null;
     this.clrtypeNs    = null;
     this.schemaName   = null;
     this.schemaNs     = null;
     this.baseType     = null;
     this.clrTypeFlags = ClrTypeFlags.None;
     this.typeOrigin   = SchemaOrigin.None;
     this.annotations  = new List <ClrAnnotation>();
 }
Beispiel #8
0
        private void Init() {
            clrtypeName = null;
            clrtypeNs = null;
            schemaName = null;
            schemaNs = null;
            baseType = null;

            clrTypeFlags = ClrTypeFlags.None;
            typeOrigin = SchemaOrigin.None;

            annotations = new List<ClrAnnotation>();
        }
Beispiel #9
0
        private void Init()
        {
            clrtypeName = null;
            clrtypeNs   = null;
            schemaName  = null;
            schemaNs    = null;
            baseType    = null;

            clrTypeFlags = ClrTypeFlags.None;
            typeOrigin   = SchemaOrigin.None;

            annotations = new List <ClrAnnotation>();
        }
        private ClrPropertyInfo BuildProperty(XmlSchemaElement elem, bool fromBaseType)
        {
            string           identifierName      = this.localSymbolTable.AddLocalElement(elem);
            XmlSchemaType    schemaType          = elem.ElementSchemaType;
            XmlQualifiedName schemaTypeName      = schemaType.QualifiedName;
            string           schemaName          = elem.QualifiedName.Name;
            string           schemaNs            = elem.QualifiedName.Namespace;
            string           clrNs               = (elem.FormResolved() == XmlSchemaForm.Qualified ? this.configSettings.GetClrNamespace(schemaNs) : string.Empty);
            SchemaOrigin     typeRefOrigin       = SchemaOrigin.Fragment;
            bool             isTypeRef           = false;
            bool             anonymousType       = schemaTypeName.IsEmpty;
            XmlSchemaObject  schemaObject        = schemaType;
            ArrayList        substitutionMembers = null;

            if (elem.IsGlobal())
            {
                substitutionMembers = this.IsSubstitutionGroupHead(elem);
                schemaTypeName      = elem.QualifiedName;
                isTypeRef           = true;
                typeRefOrigin       = SchemaOrigin.Element;
                schemaObject        = this.schemas.GlobalElements[schemaTypeName];
                anonymousType       = false;
            }
            ClrTypeReference typeRef = this.BuildTypeReference(schemaObject, schemaTypeName, anonymousType, true);

            typeRef.Origin    = typeRefOrigin;
            typeRef.IsTypeRef = isTypeRef;
            if ((!anonymousType ? false : !fromBaseType))
            {
                this.localSymbolTable.AddAnonymousType(identifierName, elem, typeRef);
            }
            ClrPropertyInfo propertyInfo = new ClrPropertyInfo(identifierName, schemaNs, schemaName, this.GetOccurence(elem))
            {
                Origin        = SchemaOrigin.Element,
                FromBaseType  = fromBaseType,
                TypeReference = typeRef
            };

            if (substitutionMembers != null)
            {
                propertyInfo.SubstitutionMembers = substitutionMembers;
            }
            return(propertyInfo);
        }
Beispiel #11
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;
         }
         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;
 }
        private void SetUnionCatchAll(
            object value,
            string propertyName,
            XTypedElement container,
            XName itemXName,
            SimpleTypeValidator typeDef,
            SchemaOrigin origin)
        {
            UnionSimpleTypeValidator unionDef =
                typeDef as UnionSimpleTypeValidator;

            Debug.Assert(unionDef != null);

            SimpleTypeValidator matchingType = null;
            object typedValue;
            Exception e = unionDef.TryParseValue(
                value,
                XTypedServices.NameTable,
                new XNamespaceResolver(container.GetUntyped()),
                out matchingType,
                out typedValue);

            if (e != null)
            {
                throw new LinqToXsdException(propertyName, e.Message);
            }
            else
            {
                if (matchingType is ListSimpleTypeValidator)
                {
                    ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator;
                    switch (origin)
                    {
                        case SchemaOrigin.Element:
                            SetListElement(itemXName, value, listType.ItemType.DataType);
                            break;
                        case SchemaOrigin.Text:
                            SetListValue(value, listType.ItemType.DataType);
                            break;
                        case SchemaOrigin.Attribute:
                            SetListAttribute(itemXName, value, listType.ItemType.DataType);
                            break;
                        default:
                            break;
                    }

                }
                else
                {
                    switch (origin)
                    {
                        case SchemaOrigin.Element: SetElement(itemXName, value, matchingType.DataType); break;
                        case SchemaOrigin.Text: SetValue(value, matchingType.DataType); break;
                        case SchemaOrigin.Attribute: SetAttribute(itemXName, value, matchingType.DataType); break;
                        default: break;
                    }
                }
            }
        }
Beispiel #13
0
 public static CodeMemberProperty CreateTypeOriginProperty(SchemaOrigin typeOrigin) {
     CodeTypeReference originType = new CodeTypeReference(Constants.Origin);
     CodeMemberProperty property = CreateInterfaceImplProperty(Constants.TypeOrigin, Constants.IXMetaData, originType);
     property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(originType), typeOrigin == SchemaOrigin.Element ? "Element" : "Fragment")));
     return property;
 }
Beispiel #14
0
 public MultiSchemaQuery(string connName, SchemaOrigin origin)
 {
     this.ConnectionName = connName;
     this.Origin = origin;
     _query = new List<SchemaQuery>();
 }
Beispiel #15
0
 public MultiSchemaQuery(string connName, SchemaOrigin origin)
 {
     this.ConnectionName = connName;
     this.Origin         = origin;
     _query = new List <SchemaQuery>();
 }