Line data Source code
1 : using System;
2 : using System.ComponentModel;
3 : using System.Globalization;
4 :
5 : namespace Cqrs.WebApi.Formatters.FormMultipart.Infrastructure.TypeConverters
6 : {
7 : /// <summary>
8 : /// Convert <see cref="DateTime"/> to ISO 8601 format string
9 : /// </summary>
10 : internal class DateTimeConverterIso8601 : DateTimeConverter
11 : {
12 0 : public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
13 : {
14 : if (value != null && value is DateTime && destinationType == typeof (string))
15 : {
16 : return ((DateTime)value).ToString("O"); // ISO 8601
17 : }
18 : return base.ConvertTo(context, culture, value, destinationType);
19 : }
20 : }
21 : }
|