Example #1
0
        private static void ReadPrimitive(XmlReader reader, NamespaceDescriptor namespaceDescriptor)
        {
            bool bEmpty = reader.IsEmptyElement;

            reader.MoveToFirstAttribute();
            var descriptor = namespaceDescriptor.CreatePrimitiveType(reader.Value);

            reader.Read();

            if (!bEmpty)
            {
                ReadEndElement(reader);
            }
        }
Example #2
0
        private static void ProcessSimpleType(NamespaceDescriptor namespaceDescriptor, XmlSchemaSimpleType simpleType)
        {
            var facets = simpleType.GetEnumerationFacets();

            if (facets.Any())
            {
                var descriptor = namespaceDescriptor.CreateEnumerationType(simpleType.Name ?? (simpleType.Parent as XmlSchemaElement)?.Name);
                foreach (var facet in facets)
                {
                    if (!descriptor.Items.Any(_ => _.Name == facet.Value))
                    {
                        descriptor.AddItem(facet.Value);
                    }
                }
            }
            else
            {
                var descriptor = namespaceDescriptor.CreatePrimitiveType(simpleType.Name);
            }
        }
Example #3
0
        private static void processNamespace(NamespaceDesc ns, NamespaceDescriptor namespaceDescriptor)
        {
            if (ns.Items != null)
            {
                foreach (var t in ns.Items)
                {
                    if (t is Composite composite)
                    {
                        var descriptor = namespaceDescriptor.CreateCompositeType(composite.name);
                        if (composite.Field != null)
                        {
                            foreach (var field in composite.Field)
                            {
                                var newField = descriptor.AddField(field.name, field.type, field.isCollectionSpecified && field.isCollection);
                                if (field.AttachedData != null)
                                {//TODO hack for boolean values
                                    field.AttachedData.Select(_ => new KeyValuePair <string, object>(_.key, _.value == "True" ? (object)true : _.value)).ToList().ForEach(_ => newField.AttachedData.Add(_));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (t is Primitive primitive)
                        {
                            var descriptor = namespaceDescriptor.CreatePrimitiveType(primitive.name);
                        }
                        else
                        {
                            if (t is Enumeration enumeration)
                            {
                                var descriptor = namespaceDescriptor.CreateEnumerationType(enumeration.name);

                                int i = 0;
                                foreach (var item in enumeration.Item)
                                {
                                    if (item.valueSpecified)
                                    {
                                        descriptor.AddItem(item.name, item.value);
                                        i = item.value;
                                    }
                                    else
                                    {
                                        descriptor.AddItem(item.name, i);
                                    }
                                    ++i;
                                }
                            }
                            else
                            {
                                throw new Exception("Unknown type");
                            }
                        }
                    }
                }
            }

            if (ns.Namespace != null)
            {
                foreach (var n in ns.Namespace)
                {
                    processNamespace(n, namespaceDescriptor.GetOrCreateNamespace(n.name));
                }
            }
        }