Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created June 20, 2016 10:46
Show Gist options
  • Save lbargaoanu/ddb765c7ed8a32d19954a49d5667272f to your computer and use it in GitHub Desktop.
Save lbargaoanu/ddb765c7ed8a32d19954a49d5667272f to your computer and use it in GitHub Desktop.
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