Skip to content

Instantly share code, notes, and snippets.

@vicentedealencar
Created June 11, 2013 03:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vicentedealencar/5754256 to your computer and use it in GitHub Desktop.
Save vicentedealencar/5754256 to your computer and use it in GitHub Desktop.
using AutoMapper;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Miyagi.Common.Helpers
{
public static class AutoMapperExtensions
{
public static List<TResult> MapTo<TResult>(this IEnumerable self)
{
if (self == null)
throw new ArgumentNullException();
return (List<TResult>)Mapper.Map(self, self.GetType(), typeof(List<TResult>));
}
public static TResult MapTo<TResult>(this object self)
{
if (self == null)
throw new ArgumentNullException();
return (TResult)Mapper.Map(self, self.GetType(), typeof(TResult));
}
public static TResult MapPropertiesToInstance<TResult>(this object self, TResult value)
{
if (self == null)
throw new ArgumentNullException();
return (TResult)Mapper.Map(self, value, self.GetType(), typeof(TResult));
}
public static TResult DynamicMapTo<TResult>(this object self)
{
if (self == null)
throw new ArgumentNullException();
return (TResult)Mapper.DynamicMap(self, self.GetType(), typeof(TResult));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment