C
C#M B V R K

IValueResolver won't work with AutoMapper

Hi guys , hope all of you doing well, I'm recently working on a project where I need to convert a special type of values to Datetime as the following example :
public class GetLinkByIdQueryMappingProfile: Profile
{
public GetLinkByIdQueryMappingProfile()
{
CreateMap<GetLinkByIdQuery, GetLinkByIdRequest>();

CreateMap<GetLinkByIdResponse, GetLinkByIdQueryResultDTO>()
.ForMember(dest => dest.CreationDateAndTime, opt => opt.MapFrom(src => src.Link.CreationDateAndTime.ToDateTime()))
.ForMember(dest => dest.ExpirationDateAndTime, opt => opt.MapFrom(src => src.Link.ExpirationDateAndTime.ToDateTime()))
.ForMember(dest => dest.IsActive, opt => opt.MapFrom(src => src.Link.IsActive));
}
}
public class GetLinkByIdQueryMappingProfile: Profile
{
public GetLinkByIdQueryMappingProfile()
{
CreateMap<GetLinkByIdQuery, GetLinkByIdRequest>();

CreateMap<GetLinkByIdResponse, GetLinkByIdQueryResultDTO>()
.ForMember(dest => dest.CreationDateAndTime, opt => opt.MapFrom(src => src.Link.CreationDateAndTime.ToDateTime()))
.ForMember(dest => dest.ExpirationDateAndTime, opt => opt.MapFrom(src => src.Link.ExpirationDateAndTime.ToDateTime()))
.ForMember(dest => dest.IsActive, opt => opt.MapFrom(src => src.Link.IsActive));
}
}
As yiou will notice that many times I will need to manually tell the Automapper how to convert the Google.Protobuf.WellKnownTypes.Timestamp date and time to C# DateTime So, I read before a bout something called IValueResolver in Automapper, so I created my custom IValueResolver to do this job instead of repteat it like the following :
public class GoogleTimestampToDateTimeValueResolver : IValueResolver<Timestamp, DateTime, DateTime>
{
public DateTime Resolve(Timestamp source, DateTime destination, DateTime destMember, ResolutionContext context)
{
return source.ToDateTime();
}
}
public class GoogleTimestampToDateTimeValueResolver : IValueResolver<Timestamp, DateTime, DateTime>
{
public DateTime Resolve(Timestamp source, DateTime destination, DateTime destMember, ResolutionContext context)
{
return source.ToDateTime();
}
}
Bu after using it like the following
.ForMember(dest => dest.CreationDateAndTime, opt => opt.MapFrom<GoogleTimestampToDateTimeValueResolver>())
.ForMember(dest => dest.ExpirationDateAndTime, opt => opt.MapFrom<GoogleTimestampToDateTimeValueResolver>())
.ForMember(dest => dest.CreationDateAndTime, opt => opt.MapFrom<GoogleTimestampToDateTimeValueResolver>())
.ForMember(dest => dest.ExpirationDateAndTime, opt => opt.MapFrom<GoogleTimestampToDateTimeValueResolver>())
I got a Compile-Time error saying the message in the attached picture Please any help to fix this issue ? Massive thanks in advance <3
No description
D
dreadfullydistinct43d ago
I have some resolvers working and the signature I use is IValueResolver<CharaList, DbPlayerCharaData, ushort>, so IValueResolver<TRootStartingType, TRootDestinationType, TProperty>
MBV
M B V R K43d ago
Should the Resolver return the original object of class that used iduring mapping ?
D
dreadfullydistinct43d ago
I want to say it returns the value but $tias
MBV
M B V R K43d ago
But that will be strongly typed, and I want that resolver to be Generic
D
dreadfullydistinct43d ago
You can probably make it generic and pass the generics into the interface def But I have never done that before
Want results from more Discord servers?
Add your server
More Posts
Help with concurrency blocking issueI have a small app that runs CPU bound on multiple threads (amount of processors) On one PC it workFrontend not workingI dont really keen on frontend but I think have some knowledge about it would be nice, I'm learning JsonSerializerOptionsTo be continuedC# Dictionary questionHi, if i have a dictionary in C# defined like so: `Dictionary<string, List<int>> test;` and I do `Li✅ Avalonia not showing rows in datagridThere are no rows in my datagrid in Avalonia, the headers are visible. I've checked if my list is emInfinite loop```c# /// ------------------------------------------------------------ /// <summary> /// Creates a sHow to connect my c# backend with the frontend?Hello, I created a ASP NET Core Web Api project with the command dotnet new webapi -minimal. In my ✅ Using `Func<ReadOnlySpan<char>,bool>` but not allowed due to Pointer TypeI am building a parser, and performance is of concern. So instead of allocating infinite strings wheconcurrency and atomicity Asp.net core web api and efcorelet's say there's an endpoint called AssingUser() ,this endpoint assigns one donation to this currenBuilding a generic repository for mongodbhello folks I was thinking build a generic repository structure for mongodb. but someday if i want Reading large xml file from archive by using XmlReader in Parallel modeHello 👋. I am looking for how can I read data from archive xml file in Parallel mode. I have archiResizing the Console window - Console ApplicationHi there, I'm trying to resize the console window in a Console Application. I have tried multiple ✅ Creating a datetime with a timezoneHow do I create a `DateTime` with `new DateTime(2010, 05, 12);` and give it a specific `TimeZoneInfoCustom Newtonsoft JSON deserializationI have a dictionary where: - The key will always be a string - The value will be either: - string Issue with Form.Close() in WinformsI have a custom form called CustomMessageBox In that form, I have a method that defines a button clIssue with IMGUI.Net.Hello, I am creating an ImGUI application and It doesn't let me move the ui across my entire screen,Issue with deserializing Enums in saved JSONHey, I've been trying to deserialize a list of cards I serialized in C#, the issue I'm having is it From HttpClient, can I save/copy the request to share with someone?Is there a way to copy raw request details? For example, I'm looking for a similar output like: -3D Unity RaycastingHi guys, currently working on a puzzle game involving lasers and mirrors, however, have hit a brick Computer Science - Computer ArchitectureOn a 64 bit system (where the bus length and word size are 64 bits) how would we determine the ammou