private void AssertComplexTypeHasNoDuplicateChildElements(XmlComplexType complexType) { foreach (var childElement in complexType.PossibleChildElements) { var childrenWithSameName = complexType.PossibleChildElements.Count(c => c.Name == childElement.Name); Assert.Equal(1, childrenWithSameName); } }
private XmlType GetInlineXmlType(XElement element) { var typeName = "InlineComplexType_" + Guid.NewGuid(); var typeElement = GetInlineTypeDefinition(element); var allowedChildElements = GetAllowedChildElements(typeElement); var result = new XmlComplexType { Name = typeName, PossibleChildElements = allowedChildElements, Attributes = GetAttributesForElement(typeElement) }; return(result); }
private XmlType GetReferencedXmlType(XElement element) { var typeName = element.Attributes().Single(a => a.Name == "type").Value; if (_parsedTypes.ContainsKey(typeName)) { return(GetPreviouslyParsedType(typeName)); } var result = new XmlComplexType { Name = typeName }; _parsedTypes.Add(typeName, result); var typeElement = GetTypeDefinition(typeName); var allowedChildElements = GetAllowedChildElements(typeElement); result.PossibleChildElements = allowedChildElements; result.Attributes = GetAttributesForElement(typeElement); return(result); }
private void GenerateElementsCheckingCode(XmlComplexType xmlType) { if (!xmlType.PossibleChildElements.Any()) { return; } _stringBuilder.AppendLine($"foreach (var {CHILD_ELEMENT_VARIABLE_NAME} in {CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Elements().ToList())"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { for (var i = 0; i < xmlType.PossibleChildElements.Count; i++) { var element = xmlType.PossibleChildElements[i]; _stringBuilder.AppendLine($"{(i == 0 ? "" : "else ")}if ({CHILD_ELEMENT_VARIABLE_NAME}.Name.LocalName.Equals(\"{element.Name}\", StringComparison.OrdinalIgnoreCase))"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { XmlElementNameCorrectorCodeGenerator.GenerateElementNameCorrector(element, _stringBuilder, CHILD_ELEMENT_VARIABLE_NAME); var elementCheckMethodName = XmlCodeGeneratorMethodNameProvider.GetNameForElementTypeCheckMethod(element.Type); _stringBuilder.AppendLine($"{elementCheckMethodName}({CHILD_ELEMENT_VARIABLE_NAME});"); } } } }