Skip to content

Instantly share code, notes, and snippets.

@kobi
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobi/3508e9f5522a13e1b66b to your computer and use it in GitHub Desktop.
Save kobi/3508e9f5522a13e1b66b to your computer and use it in GitHub Desktop.
Example output for Stack Overflow question: How to simplify repeating if-then-assign construction? - http://stackoverflow.com/a/29918452/7586
// !!!
// !!! Do not modify this file, it is automatically generated. Change the .tt file instead. !!!
// !!!
namespace Your.Mapper
{
partial class Mapper
{
/// <summary>
/// Set <paramref name="target"/> properties by copying them from <paramref name="source"/>.
/// </summary>
/// <remarks>Mapping:<br/>
/// <see cref="ConsoleApplicationT4So29913514.Student.Title"/> → <see cref="ConsoleApplicationT4So29913514.StudentRecord.EntityTitle"/> <br/>
/// <see cref="ConsoleApplicationT4So29913514.Student.StudentId"/> → <see cref="ConsoleApplicationT4So29913514.StudentRecord.Id"/> <br/>
/// <see cref="ConsoleApplicationT4So29913514.Student.Name"/> → <see cref="ConsoleApplicationT4So29913514.StudentRecord.Name"/> <br/>
/// <see cref="ConsoleApplicationT4So29913514.Student.LuckyNumber"/> → <see cref="ConsoleApplicationT4So29913514.StudentRecord.LuckyNumber"/> <br/>
/// </remarks>
/// <returns><c>true</c> if any property was changed, <c>false</c> if all properties were the same.</returns>
public bool ModifyExistingEntity(ConsoleApplicationT4So29913514.Student source, ConsoleApplicationT4So29913514.StudentRecord target)
{
bool dirty = false;
if (target.EntityTitle != source.Title)
{
dirty = true;
target.EntityTitle = source.Title;
}
if (target.Id != source.StudentId)
{
dirty = true;
target.Id = source.StudentId;
}
if (target.Name != source.Name)
{
dirty = true;
target.Name = source.Name;
}
if (target.LuckyNumber != source.LuckyNumber)
{
dirty = true;
target.LuckyNumber = source.LuckyNumber;
}
return dirty;
}
/// <summary>
/// Set <paramref name="target"/> properties by copying them from <paramref name="source"/>.
/// </summary>
/// <remarks>Mapping:<br/>
/// <see cref="ConsoleApplicationT4So29913514.Car.Color"/> → <see cref="ConsoleApplicationT4So29913514.RaceCar.Color"/> <br/>
/// <see cref="ConsoleApplicationT4So29913514.Car.Driver"/> → <see cref="ConsoleApplicationT4So29913514.RaceCar.Driver"/> <br/>
/// <see cref="ConsoleApplicationT4So29913514.Car.Driver.Length"/> → <see cref="ConsoleApplicationT4So29913514.RaceCar.DriverNameDisplayWidth"/> <br/>
/// </remarks>
/// <returns><c>true</c> if any property was changed, <c>false</c> if all properties were the same.</returns>
public bool ModifyExistingEntity(ConsoleApplicationT4So29913514.Car source, ConsoleApplicationT4So29913514.RaceCar target)
{
bool dirty = false;
if (target.Color != source.Color)
{
dirty = true;
target.Color = source.Color;
}
if (target.Driver != source.Driver)
{
dirty = true;
target.Driver = source.Driver;
}
if (target.DriverNameDisplayWidth != source.Driver.Length)
{
dirty = true;
target.DriverNameDisplayWidth = source.Driver.Length;
}
return dirty;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment