Created
June 11, 2013 03:12
-
-
Save vicentedealencar/5754256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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