Common: add converter
This commit is contained in:
parent
48d2685e67
commit
fee7a2ad72
@ -23,11 +23,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using ASC.Common.Mapping.PrimitiveTypeConverters;
|
||||
|
||||
namespace ASC.Common.Mapping;
|
||||
|
||||
public class MappingProfile : Profile
|
||||
{
|
||||
public MappingProfile() => Array.ForEach(AppDomain.CurrentDomain.GetAssemblies(), a => ApplyMappingsFromAssembly(a));
|
||||
public MappingProfile()
|
||||
{
|
||||
Array.ForEach(AppDomain.CurrentDomain.GetAssemblies(), a => ApplyMappingsFromAssembly(a));
|
||||
ApplyPrimitiveMappers();
|
||||
}
|
||||
|
||||
private void ApplyMappingsFromAssembly(Assembly assembly)
|
||||
{
|
||||
@ -50,4 +56,10 @@ public class MappingProfile : Profile
|
||||
methodInfo?.Invoke(instance, new object[] { this });
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyPrimitiveMappers()
|
||||
{
|
||||
CreateMap<long, DateTime>().ReverseMap()
|
||||
.ConvertUsing<TimeConverter>();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
namespace ASC.Common.Mapping.PrimitiveTypeConverters;
|
||||
|
||||
public class TimeConverter : ITypeConverter<long, DateTime>, ITypeConverter<DateTime, long>
|
||||
{
|
||||
public DateTime Convert(long source, DateTime destination, ResolutionContext context)
|
||||
{
|
||||
return new DateTime(source);
|
||||
}
|
||||
|
||||
public long Convert(DateTime source, long destination, ResolutionContext context)
|
||||
{
|
||||
return source.Ticks;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user