public static MapperNameConvention CreateConvention() { var convention = new MapperNameConvention(); convention.Namespace = "LegacyTextBuilder"; convention.ClassShortName = "Mapper"; return(convention); }
public static string CreateText(LegacyMapContext context) { Convention = CreateConvention(); var srcProperties = context.SrcType.GetProperties(); var destProperties = context.DestType.GetProperties(); var builder = new StringBuilder(); string srcParameterName = "src"; string destParameterName = "dest"; string methodName = Convention.GetMapperMethodName(context.SrcType, context.DestType); builder.AppendLine("using System; "); builder.AppendLine("using HappyMapper; "); builder.AppendLine($"namespace {Convention.Namespace} "); builder.AppendLine("{ "); builder.AppendLine($" public static class {Convention.ClassShortName} "); builder.AppendLine(" { "); builder.AppendLine($" public static void {methodName}"); builder.AppendLine($"({context.SrcType.FullName} {srcParameterName},"); builder.AppendLine($" {context.DestType.FullName} {destParameterName})"); builder.AppendLine(" {"); string assignments = CreatePropertiesAssignments(srcProperties, destProperties, srcParameterName, destParameterName); builder.AppendLine(assignments); builder.AppendLine(" }"); builder.AppendLine(" } "); builder.AppendLine("}"); return(builder.ToString()); }