Exemplo n.º 1
0
        protected override void VisitType(CodeTypeDeclaration type)
        {
            _fieldDocumentationLookup = new Dictionary <string, XmlSchemaDocumentation>();

            var xsdComplexType = type.GetXmlSchemaType() as XmlSchemaComplexType;

            if (xsdComplexType == null)
            {
                return;
            }

            // Add comment to class
            var xsdDocNode = xsdComplexType.Annotation?.Items.OfType <XmlSchemaDocumentation>().FirstOrDefault();

            if (xsdDocNode != null)
            {
                var textLines = GetDocumentation(xsdDocNode);
                foreach (var line in textLines)
                {
                    type.Comments.Add(new CodeCommentStatement(line, true));
                }
            }

            if (type.Members.OfType <CodeMemberField>().All(x => x.HasAnyXmlTextAttribute()))
            {
                // Types without own properties
                return;
            }

            switch (xsdComplexType.ContentType)
            {
            case XmlSchemaContentType.TextOnly:     // simpleContent, DateType
                var sext = (XmlSchemaSimpleContentExtension)((XmlSchemaSimpleContent)xsdComplexType.ContentModel).Content;
                _fieldDocumentationLookup = sext.Attributes.OfType <XmlSchemaAttribute>().ToDictionary(k => k.Name, v => v.Annotation?.Items.OfType <XmlSchemaDocumentation>().First());
                break;

            case XmlSchemaContentType.Empty:
                break;

            case XmlSchemaContentType.ElementOnly:
            case XmlSchemaContentType.Mixed:
                if (xsdComplexType.ContentTypeParticle is XmlSchemaSequence)
                {
                    var schemaSequence = xsdComplexType.ContentTypeParticle as XmlSchemaSequence;
                    _fieldDocumentationLookup = schemaSequence.Items.OfType <XmlSchemaElement>().ToDictionary(k => k.QualifiedName.Name, v => v.Annotation?.Items.OfType <XmlSchemaDocumentation>().FirstOrDefault());
                }
                else if (xsdComplexType.ContentTypeParticle is XmlSchemaChoice)
                {
                    var schemaChoice = xsdComplexType.ContentTypeParticle as XmlSchemaChoice;
                    _fieldDocumentationLookup = schemaChoice.Items.OfType <XmlSchemaElement>().ToDictionary(k => k.QualifiedName.Name, v => v.Annotation?.Items.OfType <XmlSchemaDocumentation>().FirstOrDefault());
                }
                break;
            }

            base.VisitType(type);
        }