Example #1
0
        void DoImport(XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
        {
            CodeNamespace     cns = null;
            CodeTypeReference clrRef;

            cns    = GetCodeNamespace(qname);
            clrRef = new CodeTypeReference(cns.Name.Length > 0 ? cns.Name + "." + qname.Name : qname.Name);

            var td = new CodeTypeDeclaration()
            {
                Name           = GetUniqueName(CodeIdentifier.MakeValid(qname.Name), cns),
                TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public
            };

            cns.Types.Add(td);

            var info = new TypeImportInfo()
            {
                ClrType = clrRef, XsdType = type, XsdTypeName = qname
            };

            imported_types.Add(info);

            var st = type as XmlSchemaSimpleType;

            if (st != null)
            {
                ImportSimpleType(td, schemas, st, qname);
            }
            else
            {
                var ct = (XmlSchemaComplexType)type;
                var sc = ct.ContentModel as XmlSchemaSimpleContent;
                if (sc != null)
                {
                    if (sc.Content is XmlSchemaSimpleContentExtension)
                    {
                        throw new InvalidDataContractException(String.Format("complex type '{0}' with simple content extension is not supported", type.QualifiedName));
                    }
                }
                if (!ImportComplexType(td, schemas, ct, qname))
                {
                    cns.Types.Remove(td);
                    if (cns.Types.Count == 0)
                    {
                        CodeCompileUnit.Namespaces.Remove(cns);
                    }
                }

                foreach (var impinfo in imported_types)
                {
                    for (; impinfo.KnownTypeOutputIndex < impinfo.KnownClrTypes.Count; impinfo.KnownTypeOutputIndex++)
                    {
                        td.CustomAttributes.Add(new CodeAttributeDeclaration(
                                                    new CodeTypeReference(typeof(KnownTypeAttribute)),
                                                    new CodeAttributeArgument(new CodeTypeOfExpression(impinfo.KnownClrTypes [impinfo.KnownTypeOutputIndex]))));
                    }
                }
            }
        }
Example #2
0
		static XsdDataContractExporter ()
		{
			var l = new List<TypeImportInfo> ();
			predefined_types = l;
			if (!MSTypesSchema.IsCompiled)
				MSTypesSchema.Compile (null);
			foreach (XmlSchemaElement el in MSTypesSchema.Elements.Values) {
				var typeName = el.ElementSchemaType.QualifiedName;
				var info = new TypeImportInfo () {
					RootElementName = el.QualifiedName,
					SchemaType = typeName.Namespace == XmlSchema.Namespace ? null : el.ElementSchemaType,
					SchemaTypeName = typeName,
					ClrType = GetPredefinedTypeFromQName (typeName) };
				l.Add (info);
			}
		}
Example #3
0
        void DoImport(XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
        {
            CodeNamespace     cns = null;
            CodeTypeReference clrRef;

            cns    = GetCodeNamespace(qname);
            clrRef = new CodeTypeReference(cns.Name.Length > 0 ? cns.Name + "." + qname.Name : qname.Name);

            var td = new CodeTypeDeclaration();

            td.Name = CodeIdentifier.MakeValid(qname.Name);
            cns.Types.Add(td);

            var info = new TypeImportInfo()
            {
                ClrType = clrRef, XsdType = type, XsdTypeName = qname
            };

            imported_types.Add(info);

            var st = type as XmlSchemaSimpleType;

            if (st != null)
            {
                ImportSimpleType(td, schemas, st, qname);
            }
            else
            {
                var ct = (XmlSchemaComplexType)type;
                var sc = ct.ContentModel as XmlSchemaSimpleContent;
                if (sc != null)
                {
                    if (sc.Content is XmlSchemaSimpleContentExtension)
                    {
                        throw new InvalidDataContractException(String.Format("complex type '{0}' with simple content extension is not supported", type.QualifiedName));
                    }
                }
                if (!ImportComplexType(td, schemas, ct, qname))
                {
                    cns.Types.Remove(td);
                    if (cns.Types.Count == 0)
                    {
                        CodeCompileUnit.Namespaces.Remove(cns);
                    }
                }
            }
        }
Example #4
0
        static XsdDataContractExporter()
        {
            var l = new List <TypeImportInfo> ();

            predefined_types = l;
            if (!MSTypesSchema.IsCompiled)
            {
                MSTypesSchema.Compile(null);
            }
            foreach (XmlSchemaElement el in MSTypesSchema.Elements.Values)
            {
                var typeName = el.ElementSchemaType.QualifiedName;
                var info     = new TypeImportInfo()
                {
                    RootElementName = el.QualifiedName,
                    SchemaType      = typeName.Namespace == XmlSchema.Namespace ? null : el.ElementSchemaType,
                    SchemaTypeName  = typeName,
                    ClrType         = GetPredefinedTypeFromQName(typeName)
                };
                l.Add(info);
            }
        }
Example #5
0
		void DoImport (XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
		{
			CodeNamespace cns = null;
			CodeTypeReference clrRef;
			cns = GetCodeNamespace (qname.Namespace);
			clrRef = new CodeTypeReference (cns.Name.Length > 0 ? cns.Name + "." + qname.Name : qname.Name);

			var td = new CodeTypeDeclaration () {
				Name = GetUniqueName (CodeIdentifier.MakeValid (qname.Name), cns),
				TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public,
				IsPartial = true };
			cns.Types.Add (td);

			var info = new TypeImportInfo () { ClrType = clrRef, XsdType = type,  XsdTypeName = qname };
			imported_types.Add (info);

			var st = type as XmlSchemaSimpleType;
			if (st != null) {
				ImportSimpleType (td, schemas, st, qname);
			} else {
				var ct = (XmlSchemaComplexType) type;
				var sc = ct.ContentModel as XmlSchemaSimpleContent;
				if (sc != null) {
					if (sc.Content is XmlSchemaSimpleContentExtension)
						throw new InvalidDataContractException (String.Format ("complex type '{0}' with simple content extension is not supported", type.QualifiedName));
				}
				if (!ImportComplexType (td, schemas, ct, qname)) {
					cns.Types.Remove (td);
					if (cns.Types.Count == 0)
						CodeCompileUnit.Namespaces.Remove (cns);
				}

				foreach (var impinfo in imported_types)
					for (; impinfo.KnownTypeOutputIndex < impinfo.KnownClrTypes.Count; impinfo.KnownTypeOutputIndex++)
						td.CustomAttributes.Add (new CodeAttributeDeclaration (
							new CodeTypeReference (typeof (KnownTypeAttribute)),
							new CodeAttributeArgument (new CodeTypeOfExpression (impinfo.KnownClrTypes [impinfo.KnownTypeOutputIndex]))));
			}
		}
		void DoImport (XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
		{
			CodeNamespace cns = null;
			CodeTypeReference clrRef;
			cns = GetCodeNamespace (qname);
			clrRef = new CodeTypeReference (cns.Name.Length > 0 ? cns.Name + "." + qname.Name : qname.Name);

			var td = new CodeTypeDeclaration ();
			td.Name = CodeIdentifier.MakeValid (qname.Name);
			cns.Types.Add (td);

			var info = new TypeImportInfo () { ClrType = clrRef, XsdType = type,  XsdTypeName = qname };
			imported_types.Add (info);

			var st = type as XmlSchemaSimpleType;
			if (st != null) {
				ImportSimpleType (td, schemas, st, qname);
			} else {
				var ct = (XmlSchemaComplexType) type;
				var sc = ct.ContentModel as XmlSchemaSimpleContent;
				if (sc != null) {
					if (sc.Content is XmlSchemaSimpleContentExtension)
						throw new InvalidDataContractException (String.Format ("complex type '{0}' with simple content extension is not supported", type.QualifiedName));
				}
				if (!ImportComplexType (td, schemas, ct, qname)) {
					cns.Types.Remove (td);
					if (cns.Types.Count == 0)
						CodeCompileUnit.Namespaces.Remove (cns);
				}
			}
		}