Witam.
Mam taką funkcję:
public static DateTime ToDateTime(this string date)
{
return DateTime.ParseExact(date, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
}
Problemem jest zmienna date, która ma różne postacie: 2015-12-01T0000 + 00:00, 12/31/2018 0100 itp.
Podczas uruchamiania mam błąd:
System.FormatException
HResult=0x80131537
Message=The string was not recognized as a valid DateTime element.
Source=mscorlib
Ślad stosu:
w System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
w System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
w InsuranceService.Common.ExtensionMethods.StringExtensionMethods.ToDateTime(String date) w StringExtensionMethods.cs:wiersz 10
w AutoMapper.Internal.DelegateBasedResolver2.Resolve(ResolutionResult source) w AutoMapper.NullReferenceExceptionSwallowingResolver.Resolve(ResolutionResult source) w AutoMapper.PropertyMap.<>c.<ResolveValue>b__44_0(ResolutionResult current, IValueResolver resolver) w System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable
1 source, TAccumulate seed, Func`3 func)
w AutoMapper.PropertyMap.ResolveValue(ResolutionContext context)
w AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, Object mappedObject, PropertyMap propertyMap)
Wie ktoś może jak to naprawić?