Created
July 16, 2012 22:26
-
-
Save cyberzed/3125486 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
| public class ICC | |
| { | |
| public ICC(string number) | |
| { | |
| Number = number; | |
| } | |
| public string Number { get; private set; } | |
| } |
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
| public class ICCConvertionPattern : IConversionPattern<ICC, string> | |
| { | |
| public Expression<Func<ICC, IMapper, MappingContext, string>> BuildConversionExpression(MappingStep mapping) | |
| { | |
| return (icc, mapper, context) => icc != null ? icc.Number : string.Empty; | |
| } | |
| } |
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
| public class PIN | |
| { | |
| public PIN(string code) | |
| { | |
| Code = code; | |
| } | |
| public string Code { get; set; } | |
| } |
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
| public class PINConvertionPattern : IConversionPattern<PIN, string> | |
| { | |
| public Expression<Func<PIN, IMapper, MappingContext, string>> BuildConversionExpression(MappingStep mapping) | |
| { | |
| return (pin, mapper, context) => pin != null ? pin.Code : string.Empty; | |
| } | |
| } |
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
| internal class Program | |
| { | |
| private static void Main() | |
| { | |
| var mapBuilder = new MapperBuilder(); | |
| mapBuilder.Settings.AddConversionPatternType(typeof (ICCConvertionPattern)); | |
| mapBuilder.Settings.AddConversionPatternType(typeof (PINConvertionPattern)); | |
| var mapper = mapBuilder.BuildMapper(); | |
| var sim = new SIM | |
| { | |
| ICC = new ICC("12345678901234567890"), | |
| PIN1 = new PIN("1234"), | |
| PIN2 = new PIN("5678") | |
| }; | |
| var simDto = mapper.Convert<SIMDto>(sim); | |
| } | |
| } |
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
| public class SIM | |
| { | |
| public ICC ICC { get; set; } | |
| public PIN PIN1 { get; set; } | |
| public PIN PIN2 { get; set; } | |
| } |
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
| public class SIMDto | |
| { | |
| public string ICC { get; set; } | |
| public string PIN1 { get; set; } | |
| public string PIN2 { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment