private string MappingMethod(Mapper mapper) { var builder = new StringBuilder(); builder.AppendLineWithTabs($"public {EntityHandler.Entity.Name} MapToObject({EntityHandler.GetEntityLocationOnId(mapper.FromTo.To).FileLocation.GetProjectLocation}.{EntityHandler.Entity.Name} objectToMapFrom)", 0); builder.AppendLineWithTabs("{", 1); builder.AppendLineWithTabs($"var objectToMapTo = new {EntityHandler.Entity.Name}", 2); builder.AppendLineWithTabs("{", 2); foreach (var property in EntityHandler.GetClassBuilder(mapper.FromTo.To).GetNonChildCollectionProperties) { builder.AppendLineWithTabs($"{GetMappingProperty(property)},", 3); } builder.AppendLineWithTabs("};", 2); builder.Append(Environment.NewLine); foreach (var childcollectionProp in EntityHandler.GetClassBuilder(mapper.FromTo.To).GetChildCollectionProperties) { builder.AppendLineWithTabs($"foreach(var property in objectToMapFrom.{childcollectionProp.Property.Name})", 2); builder.AppendLineWithTabs("{", 2); builder.AppendLineWithTabs($"objectToMapTo.{GetMappingProperty(childcollectionProp)}", 3); builder.AppendLineWithTabs("}", 2); builder.Append(Environment.NewLine); } builder.AppendLineWithTabs("return objectToMapTo;", 2); builder.AppendLineWithTabs("}", 1); return(builder.ToString()); }
private void AddFieldsWithParameterToConstructor(ClassFile classFile, Mapper mapper) { foreach (var property in EntityHandler.GetClassBuilder(mapper.FromTo.From).GetChildChildCollectionProperties) { classFile.Constructor.AddFieldWithParameter(new Field("private", $"_{EntityHandler.GetMapperInterfaceParameter(property.Property.DataType.Type)}", EntityHandler.GetMapperInterface(property.Property.DataType.Type)), new TypeWithName($"{EntityHandler.GetMapperInterfaceParameter(property.Property.DataType.Type)}", EntityHandler.GetMapperInterface(property.Property.DataType.Type))); } }
internal static List <OutputFile> ResolveEntityFiles(EntityHandler handler) { var outputFiles = new List <OutputFile>(); if (handler.IsChanged) { outputFiles.AddRange(handler.GetEntityLocations.SelectMany(x => handler.GetClassBuilder(x).Build())); if (handler.GetRepository != null && handler.GetRepository.Generate) { outputFiles.AddRange(handler.GetRepositoryBuilder.Build()); } outputFiles.AddRange(handler.GetDatabaseBuilder.Build()); if (handler.GetMappers != null && handler.GetMappers.Generate) { outputFiles.AddRange(handler.GetMappers.Mapper.SelectMany(x => handler.GetMapperBuilder.Build(x))); } } return(outputFiles); }