Last active
May 13, 2016 11:22
-
-
Save lbargaoanu/3d53df41e068da4ae2b8021b15733af0 to your computer and use it in GitHub Desktop.
#1267.cs
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
namespace Source | |
{ | |
public class Instance | |
{ | |
public Type Type { get; set; } | |
public object Definition { get; set; } | |
} | |
public sealed class Class : Instance | |
{ | |
private IList<Property> m_Properties; | |
public IList<Property> Properties | |
{ | |
get { return m_Properties ?? (m_Properties = new List<Property>()); } | |
} | |
} | |
public abstract class Member : Instance | |
{ | |
public string Name { get; set; } | |
} | |
public sealed class Parameter : Member | |
{ | |
} | |
public sealed class Property : Member | |
{ | |
} | |
} | |
namespace Target | |
{ | |
public class Instance | |
{ | |
public Type Type { get; set; } | |
public Instance Definition { get; set; } | |
} | |
public sealed class Class : Instance | |
{ | |
private IList<Property> m_Properties; | |
public IList<Property> Properties { get; set; } | |
//{ | |
// get { return m_Properties ?? (m_Properties = new List<Property>()); } | |
//} | |
} | |
public abstract class Member : Instance | |
{ | |
public string Name { get; set; } | |
} | |
public sealed class Parameter : Member | |
{ | |
} | |
public sealed class Property : Member | |
{ | |
} | |
} | |
var classConfig = new MapperConfiguration(cfg => | |
{ | |
cfg.CreateMap<object, Target.Instance>() | |
.ForMember(d => d.Definition, o => o.Ignore()) | |
.ForMember(d => d.Type, o => o.Ignore()); | |
cfg.CreateMap<Source.Instance, Target.Instance>() | |
.Include<Source.Property, Target.Property>() | |
.Include<Source.Parameter, Target.Parameter>() | |
.Include<Source.Class, Target.Class>(); | |
cfg.CreateMap<Source.Class, Target.Class>(); | |
cfg.CreateMap<Source.Property, Target.Property>(); | |
cfg.CreateMap<Source.Parameter, Target.Parameter>(); | |
}); | |
classConfig.AssertConfigurationIsValid(); | |
var classMapper = classConfig.CreateMapper(); | |
var definitionLevel1 = new Source.Class { Properties = { new Source.Property { Name = "PropertyLevel_1.1" }, new Source.Property() { Name = "PropertyLevel_1.2" } } }; | |
definitionLevel1.Definition = definitionLevel1; | |
var sourceMember = new Source.Property { Name = "Some_Property_Name", Definition = definitionLevel1, Type = typeof(int) }; | |
var _result = classMapper.Map<Target.Member[]>(new[] { sourceMember }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment