Esempio n. 1
0
        public void GenerateTypeCheckingMethod(XmlType xmlType)
        {
            var checkMethodName = XmlCodeGeneratorMethodNameProvider.GetNameForAttributeCheckMethod(xmlType);

            _stringBuilder.AppendLine($"private void {checkMethodName}(XAttribute {ATTRIBUTE_VARIABLE_NAME})");
            using (new CodeGeneratorBlockWrapper(_stringBuilder))
            {
                var enumerationType = xmlType as XmlEnumerationType;
                if (enumerationType != null)
                {
                    GenerateEnumerationAttributeCheckMethod(enumerationType);
                }
                else
                {
                    _stringBuilder.AppendLine("// Only attributes with enumeration restriction are currently supported for validation");
                }
            }
        }
Esempio n. 2
0
 public static void GenerateAttributesCheckingCode(XmlTypeWithAttributes xmlType, StringBuilder stringBuilder)
 {
     if (!xmlType.Attributes.Any())
     {
         return;
     }
     stringBuilder.AppendLine($"foreach (var {CodeGeneratorConstants.ELEMENT_CHECK_METHOD_CHILD_ATTRIBUTE_VARIABLE_NAME} in {CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Attributes().ToList())");
     using (new CodeGeneratorBlockWrapper(stringBuilder))
     {
         for (var i = 0; i < xmlType.Attributes.Count; i++)
         {
             var attribute = xmlType.Attributes[i];
             stringBuilder.AppendLine($"{(i == 0 ? "" : "else ")}if ({CodeGeneratorConstants.ELEMENT_CHECK_METHOD_CHILD_ATTRIBUTE_VARIABLE_NAME}.Name.LocalName.Equals(\"{attribute.Name}\", StringComparison.OrdinalIgnoreCase))");
             using (new CodeGeneratorBlockWrapper(stringBuilder))
             {
                 var elementCheckMethodName = XmlCodeGeneratorMethodNameProvider.GetNameForAttributeCheckMethod(attribute.Type);
                 stringBuilder.AppendLine($"{elementCheckMethodName}({CodeGeneratorConstants.ELEMENT_CHECK_METHOD_CHILD_ATTRIBUTE_VARIABLE_NAME});");
                 XmlElementNameCorrectorCodeGenerator.GenerateAttributeNameCorrector(attribute, stringBuilder, CodeGeneratorConstants.ELEMENT_CHECK_METHOD_CHILD_ATTRIBUTE_VARIABLE_NAME);
             }
         }
     }
 }