internal void Persist(XmlWriter writer) { writer.WriteStartElement("Condition"); writer.WriteElementString("ColumnName", ColumnName); writer.WriteElementString("FormatType", FormatType.ToString()); writer.WriteStartElement("FormatParams"); FormatParams.Persist(writer); writer.WriteEndElement(); //FormatParams //No need to persist min/max Value. writer.WriteEndElement(); //Condition }
public static string Build() { var interfaceTemp = @"INewConvert<{TParam}, {TReturn}>"; var methodTemp = @" {TReturn} INewConvert<{TParam}, {TReturn}>.Convert({TParam} value) => {TDeclaringType}.{Name}(value);"; var interfaceSplit = ", "; var methodSplit = "\r\n"; var interfaceGroupSplit = "\r\n "; var methodGroupSplit = "\r\n"; var interfaces = new StringBuilder(); var methods = new StringBuilder(); FormatParams lastParam = null; var list = new List <MethodInfo>(); list.AddRange(typeof(ConvertAdd).GetMethods()); list.AddRange(typeof(Convert).GetMethods()); list = list.Distinct(new ConvertMethodComparer()).ToList(); list.Sort((x, y) => x.ReturnType.Name.CompareTo(y.ReturnType.Name)); foreach (var item in list) { if (item.IsStatic && item.Name.StartsWith("To") && item.ReturnType != typeof(void) && item.GetParameters().Length == 1) { var param = new FormatParams { TParam = item.GetParameters()[0].ParameterType.Name, TReturn = item.ReturnType.Name, TDeclaringType = item.DeclaringType.FullName, Name = item.Name }; if (lastParam == null || param.TReturn != lastParam.TReturn) { interfaces.Append(interfaceGroupSplit); methods.Append(methodGroupSplit); } interfaces.Append(StringHelper.Format(interfaceTemp, param)); methods.Append(StringHelper.Format(methodTemp, param)); interfaces.Append(interfaceSplit); methods.Append(methodSplit); lastParam = param; } } interfaces.Length -= interfaceSplit.Length; methods.Length -= methodSplit.Length; var codeTemp = @"using System; namespace Swifter.Tools \{ internal sealed class BasicConvert : {Interfaces} \{ public static readonly BasicConvert Instance = new BasicConvert(); private BasicConvert() \{} {Methods} } } "; var code = StringHelper.Format(codeTemp, new { Interfaces = interfaces.ToString(), Methods = methods.ToString() }); return(code.ToString()); }