Created
June 20, 2016 10:46
-
-
Save lbargaoanu/ddb765c7ed8a32d19954a49d5667272f 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
void Main() | |
{ | |
var _mapperConfiguration = new MapperConfiguration(cfg => { | |
cfg.CreateMap(typeof(NodeDto<>), typeof(NodeModel<>)); | |
cfg.CreateMap(typeof(NodeDto<>), typeof(INodeModel<>)); | |
cfg.CreateMap(typeof(INodeModel<>), typeof(NodeModel<>)); | |
}); | |
var dto = new NodeDto<int> { ID = 13, Name = "Hi" }; | |
var obj = _mapperConfiguration.CreateMapper().Map<INodeModel<int>>(dto).Dump(); | |
} | |
public interface INodeModel<T> | |
where T : struct | |
{ | |
T? ID { get; set; } | |
} | |
public interface INodeModel | |
{ | |
object ID { get; set; } | |
string Name { get; set; } | |
} | |
public class NodeModel<T> : INodeModel<T>, INodeModel | |
where T : struct | |
{ | |
public T? ID { get; set; } | |
public string Name { get; set; } | |
object INodeModel.ID | |
{ | |
get | |
{ | |
return ID; | |
} | |
set | |
{ | |
ID = value as T?; | |
} | |
} | |
} | |
public class NodeDto<T> where T : struct | |
{ | |
public T? ID { get; set; } | |
public string Name { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment