Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Created January 31, 2012 09:02
Show Gist options
  • Save alexbeletsky/1709552 to your computer and use it in GitHub Desktop.
Save alexbeletsky/1709552 to your computer and use it in GitHub Desktop.
public interface IMapper<TInput, TOutput>
{
TOutput Map(TInput input);
}
public interface ICompositeMapper<TInput, TOutput>
{
TOutput[] Map(TInput input);
}
// Implementation
public class Mapper : IMapper<XModel, Model>
{
public Model Map(XModel)
{
}
}
public class CompositeMapper : ICompositeMapper<XModel, Model>
{
public Model[] Map(XModel)
{
}
}
// Tests
public class MapperTests
{
[Test]
public void should_map()
{
var mapper = new Mapper();
var result = mapper.Map(input);
// assert result
}
}
public class CompositeMapperTests
{
[Test]
public void should_map()
{
var mapper = new CompositeMapper();
var result = mapper.Map(input);
// assert result
}
}
// Use case
public class SomeRepository : IRepository
{
public Model GetById (int id)
{
var xModel = // ask NHibernate for it..
return new Mapper().Map(xModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment