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 : public class FromStringConverterAdapter
8 0 : {
9 : private readonly Type _type;
10 :
11 : private readonly TypeConverter _typeConverter;
12 :
13 0 : public FromStringConverterAdapter(Type type, TypeConverter typeConverter)
14 : {
15 : if(type == null)
16 : throw new ArgumentNullException("type");
17 : if (typeConverter == null)
18 : throw new ArgumentNullException("typeConverter");
19 :
20 : _type = type;
21 : _typeConverter = typeConverter;
22 : }
23 :
24 0 : public object ConvertFromString(string src, CultureInfo culture)
25 : {
26 : var isUndefinedNullable = Nullable.GetUnderlyingType(_type) != null && src == "undefined";
27 : if (isUndefinedNullable)
28 : return null;
29 :
30 : return _typeConverter.ConvertFromString(null, culture, src);
31 : }
32 : }
33 : }
|