private XElement CreateElement(PropertyInfo property) { string name = MagickTypes.GetXsdName(property); string attributeTypeName = MagickTypes.GetXsdAttributeType(property); if (attributeTypeName != null) { XElement complexType = new XElement(_Namespace + "complexType"); complexType.Add(new XElement(_Namespace + "attribute", new XAttribute("name", "value"), new XAttribute("use", "required"), new XAttribute("type", attributeTypeName))); return(new XElement(_Namespace + "element", new XAttribute("name", name), complexType)); } else { return(new XElement(_Namespace + "element", new XAttribute("name", name), new XAttribute("type", MagickTypes.GetXsdElementType(property)))); } }
private XElement CreateElement(PropertyInfo property) { string name = MagickTypes.GetXsdName(property); string attributeTypeName = MagickTypes.GetXsdAttributeType(property); if (attributeTypeName != null) { XElement complexType = new XElement(_Namespace + "complexType"); complexType.Add(new XElement(_Namespace + "attribute", new XAttribute("name", "value"), new XAttribute("use", "required"), new XAttribute("type", attributeTypeName))); return(new XElement(_Namespace + "element", new XAttribute("name", name), complexType)); } else { string elementTypeName = MagickTypes.GetXsdElementType(property); if (string.IsNullOrEmpty(elementTypeName)) { throw new NotImplementedException("CreateElement: " + name); } return(new XElement(_Namespace + "element", new XAttribute("name", name), new XAttribute("type", elementTypeName))); } }
private XElement CreateElement(IEnumerable <MethodBase> methods) { XElement element = new XElement(_Namespace + "element", new XAttribute("name", MagickTypes.GetXsdName(methods.First()))); AddMethods(element, methods); return(element); }
private void ReplaceIReadDefines(XElement annotation) { annotation.ReplaceWith( from type in _Types.GetInterfaceTypes("IReadDefines") let name = MagickTypes.GetXsdName(type) select new XElement(_Namespace + "element", new XAttribute("name", name), new XAttribute("type", name))); }
private void WriteCallMethods() { foreach (MethodBase method in Methods) { string xsdMethodName = MagickTypes.GetXsdName(method); ParameterInfo[] parameters = method.GetParameters(); Write("XmlElement "); Write(xsdMethodName); Write(" = (XmlElement)element.SelectSingleNode(\""); Write(xsdMethodName); WriteLine("\");"); Write("if ("); Write(xsdMethodName); WriteLine(" != null)"); WriteStartColon(); foreach (ParameterInfo parameter in parameters) { string typeName = GetName(parameter); Write(typeName); Write(" "); Write(parameter.Name); Write("_ = XmlHelper.GetAttribute<"); Write(typeName); Write(">("); Write(xsdMethodName); Write(", \""); Write(parameter.Name); WriteLine("\");"); } Write("result."); Write(method.Name); Write("("); for (int i = 0; i < parameters.Length; i++) { if (i > 0) { Write(","); } Write(parameters[i].Name); Write("_"); } WriteLine(");"); WriteEndColon(); } }
private void ReplaceDefines(XElement annotation) { List <XElement> types = new List <XElement>(); foreach (Type interfaceType in _Types.GetInterfaceTypes("IDefines")) { XElement complexType = new XElement(_Namespace + "complexType", new XAttribute("name", MagickTypes.GetXsdName(interfaceType))); AddClass(complexType, interfaceType); types.Add(complexType); } annotation.ReplaceWith(types.ToArray()); }
private void WriteCode(string className) { Write("private "); Write(className); Write(" Create"); Write(className); WriteLine("(XmlElement parent)"); WriteStartColon(); WriteCheckNull("parent"); WriteLine("XmlElement element = (XmlElement)parent.FirstChild;"); WriteCheckNull("element"); WriteSwitch(from type in Types.GetInterfaceTypes(className) select MagickTypes.GetXsdName(type)); WriteEndColon(); }
private void WriteCode(IndentedTextWriter writer, string className) { WriteSeparator(writer); writer.Write("private "); writer.Write(className); writer.Write(" Create"); writer.Write(className); writer.WriteLine("(XmlElement parent)"); WriteStartColon(writer); CheckNull(writer, "parent"); writer.WriteLine("XmlElement element = (XmlElement)parent.FirstChild;"); CheckNull(writer, "element"); WriteSwitch(writer, from type in Types.GetInterfaceTypes(className) select MagickTypes.GetXsdName(type)); WriteEndColon(writer); }
private void WriteGetValue(PropertyInfo property) { string typeName = GetName(property); string xsdTypeName = MagickTypes.GetXsdAttributeType(property); if (xsdTypeName != null) { WriteGetElementValue(typeName, MagickTypes.GetXsdName(property)); } else { WriteCreateMethod(typeName); Write("("); WriteSelectElement(typeName, MagickTypes.GetXsdName(property)); WriteLine(");"); } }
private void AddClassAttributes(XElement complexType, IEnumerable <PropertyInfo> properties) { foreach (var property in from property in properties let typeName = MagickTypes.GetXsdAttributeType(property) where typeName != null let name = MagickTypes.GetXsdName(property) orderby name select new { Name = name, TypeName = typeName }) { complexType.Add(new XElement(_Namespace + "attribute", new XAttribute("name", property.Name), new XAttribute("type", property.TypeName))); } }
private void WriteAttributeForEach(ParameterInfo[] allParameters) { ParameterInfo[] parameters = allParameters.Where(p => MagickTypes.GetXsdAttributeType(p) != null).ToArray(); if (parameters.Length == 0) { return; } parameters = parameters.OrderBy(p => p.Name).ToArray(); WriteLine("foreach (XmlAttribute attribute in element.Attributes)"); WriteStartColon(); if (parameters.DistinctBy(p => GetName(p)).Count() == 1) { Write("arguments[attribute.Name] = Variables.GetValue<"); Write(GetName(parameters[0])); WriteLine(">(attribute);"); } else { for (int i = 0; i < parameters.Length; i++) { string xsdName = MagickTypes.GetXsdName(parameters[i]); if (i > 0) { Write("else "); } Write("if (attribute.Name == \""); Write(xsdName); WriteLine("\")"); Indent++; Write("arguments[\""); Write(xsdName); Write("\"] = "); WriteGetAttributeValue(GetName(parameters[i])); Indent--; } } WriteEndColon(); }
private void WriteElementForEach(ParameterInfo[] allParameters) { ParameterInfo[] parameters = allParameters.Where(p => MagickTypes.GetXsdAttributeType(p) == null).ToArray(); if (parameters.Length == 0) { return; } WriteLine("foreach (XmlElement elem in element.SelectNodes(\"*\"))"); WriteStartColon(); if (parameters.DistinctBy(p => GetName(p)).Count() == 1) { Write("arguments[elem.Name] = "); WriteCreateMethod(GetName(parameters[0])); WriteLine("(elem);"); } else { for (int i = 0; i < parameters.Length; i++) { string xsdName = MagickTypes.GetXsdName(parameters[i]); if (i > 0) { Write("else "); } Write("if (elem.Name == \""); Write(xsdName); WriteLine("\")"); Indent++; Write("arguments[\""); Write(xsdName); Write("\"] = "); WriteCreateMethod(GetName(parameters[i])); WriteLine("(elem);"); Indent--; } } WriteEndColon(); }
private void AddClassElements(XElement complexType, IEnumerable <PropertyInfo> properties, IEnumerable <MethodInfo> methods) { XElement sequence = new XElement(_Namespace + "sequence"); foreach (var property in from property in properties let typeName = MagickTypes.GetXsdElementType(property) where typeName != null let name = MagickTypes.GetXsdName(property) orderby name select new { Name = name, TypeName = typeName }) { XElement element = new XElement(_Namespace + "element", new XAttribute("name", property.Name), new XAttribute("minOccurs", "0")); element.Add(new XAttribute("type", property.TypeName)); sequence.Add(element); } if (methods.Count() > 0) { foreach (MethodBase method in methods) { XElement element = new XElement(_Namespace + "element", new XAttribute("name", MagickTypes.GetXsdName(methods.First())), new XAttribute("minOccurs", "0"), new XAttribute("maxOccurs", "unbounded")); AddMethods(element, new MethodBase[] { method }); sequence.Add(element); } } if (sequence.HasElements) { complexType.Add(sequence); } }
protected sealed override void WriteCase(IndentedTextWriter writer, string name) { MemberInfo member = (from property in Properties where MagickTypes.GetXsdName(property).Equals(name, StringComparison.OrdinalIgnoreCase) select property).FirstOrDefault(); if (member == null) { member = (from overloads in Methods let method = overloads[overloads.Length - 1] where MagickTypes.GetXsdName(method).Equals(name, StringComparison.OrdinalIgnoreCase) select method).FirstOrDefault(); } if (ReturnType != "void") { writer.Write("return "); } writer.Write("Execute"); if (member == null) { writer.Write(char.ToUpper(name[0], CultureInfo.InvariantCulture)); writer.Write(name.Substring(1)); } else { writer.Write(GetName(member)); } writer.Write("("); if (member == null || !HasParameters(member)) { writer.Write("element, "); } writer.Write(ExecuteArgument.Split(' ').Last()); writer.WriteLine(");"); if (ReturnType == "void") { writer.WriteLine("return;"); } }
private void WriteExecute(IndentedTextWriter writer) { writer.WriteLine("[SuppressMessage(\"Microsoft.Maintainability\", \"CA1502:AvoidExcessiveComplexity\")]"); writer.WriteLine("[SuppressMessage(\"Microsoft.Maintainability\", \"CA1505:AvoidUnmaintainableCode\")]"); writer.Write("private "); writer.Write(ReturnType); writer.Write(" Execute"); writer.Write(ExecuteName); writer.Write("(XmlElement element, "); writer.Write(ExecuteArgument); writer.WriteLine(")"); WriteStartColon(writer); IEnumerable <string> names = (from property in Properties select MagickTypes.GetXsdName(property)).Concat( from method in Methods select MagickTypes.GetXsdName(method[0])).Concat( CustomMethods); WriteSwitch(writer, names); WriteEndColon(writer); }
private void WriteInvalidCombinations(MethodBase[] methods) { WriteLine("else"); Indent++; Write("throw new ArgumentException(\"Invalid argument combination for '" + MagickTypes.GetXsdName(methods[0]) + "', allowed combinations are:"); foreach (MethodBase method in methods) { Write(" ["); ParameterInfo[] parameters = method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { Write(parameters[i].Name); if (i != parameters.Length - 1) { Write(", "); } } Write("]"); } WriteLine("\");"); Indent--; }