Example #1
0
        static void WriteSequence(this SimpleClassFormatter formatter, XmlSchemaGroupBase sequence, CommandLineOptions options, Queue <XmlSchema> schemas, HashSet <XmlSchema> processedSchemas)
        {
            // Parse schema elements
            foreach (XmlSchemaElement sequenceItem in sequence.Items.OfType <XmlSchemaElement>().Where(p => p.ElementSchemaType != null))
            {
                formatter.WriteMember(sequenceItem, options, schemas, processedSchemas);
            }

            foreach (XmlSchemaGroupBase item in sequence.Items.OfType <XmlSchemaGroupBase>())
            {
                formatter.WriteSequence(item, options, schemas, processedSchemas);
            }
        }
Example #2
0
        static void WriteComplexType(this SimpleClassFormatter formatter, XmlSchemaComplexType type, String name, CommandLineOptions options, Queue <XmlSchema> schemas, HashSet <XmlSchema> processedSchemas)
        {
            String baseType = null;
            XmlSchemaComplexContentExtension extension = type.ContentModel?.Content as XmlSchemaComplexContentExtension;

            // Check if we've a extension
            if (extension != null)
            {
                // Set base type
                baseType = extension.BaseTypeName.Name.CleanName(options.CleanNames);
                // Add schema for processing
                XmlSchema schema = LoadedSchemas.Schemas().Cast <XmlSchema>().FirstOrDefault(p => p.SchemaTypes.Contains(extension.BaseTypeName));
                if (schema != null && processedSchemas.Add(schema))
                {
                    schemas.Enqueue(schema);
                }
            }

            // Open class definition
            if (options.DataContracts)
            {
                if (name == null)
                {
                    formatter.WriteAttribute(typeof(DataContractAttribute), new KeyValuePair <String, String>("Namespace", $"\"{GetSchema(type).TargetNamespace}\""));
                }
                else
                {
                    formatter.WriteAttribute(typeof(DataContractAttribute), new KeyValuePair <String, String>("Name", $"\"{name}\""), new KeyValuePair <String, String>("Namespace", $"\"{GetSchema(type).TargetNamespace}\""));
                }
            }
            formatter.BeginClass((name ?? type.Name).CleanName(options.CleanNames), baseType, isAbstract: type.IsAbstract);

            if ((type.Particle ?? extension.Particle) is XmlSchemaGroupBase sequence)
            {
                formatter.WriteSequence(sequence, options, schemas, processedSchemas);
            }
            else if (type.Particle != null)
            {
                throw new NotImplementedException();
            }

            // Close class definition
            formatter.CloseBracket();
        }