Beispiel #1
0
        public bool WriteNullable(string value, object target)
        {
            var nc = new NullableConverter(this.Property.PropertyType);

            // FormatException (thrown by ConvertFromString) is thrown as Exception.InnerException, so we've to catch directly System.Exception
            try
            {
                this.Property.SetValue(target, nc.ConvertFromString(null, this.parsingCulture, value), null);
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Beispiel #2
0
 public bool WriteNullable(string value, object target)
 {
     var nc = new NullableConverter(Property.PropertyType);
     try
     {
         // ReSharper disable AssignNullToNotNullAttribute
         Property.SetValue(target, nc.ConvertFromString(null, Thread.CurrentThread.CurrentCulture, value), null);
         // ReSharper restore AssignNullToNotNullAttribute
     }
     // FormatException (thrown by ConvertFromString) is thrown as Exception.InnerException,
     // so we've to catch directly System.Exception
     catch (Exception)
     {
         return false;
     }
     return true;
 }
Beispiel #3
0
        private bool SetNullableValue(string value, object options)
        {
            var nc = new NullableConverter(_field.FieldType);

            try
            {
                lock (_setValueLock)
                {
                    _field.SetValue(options, nc.ConvertFromString(null, CultureInfo.InvariantCulture, value));
                }
            }
            // the FormatException (thrown by ConvertFromString) is thrown as Exception.InnerException,
            // so we've catch directly Exception
            catch (Exception) 
            {
                return false;
            }

            return true;
        }
Beispiel #4
0
 private bool SetNullableValue(string value, object options)
 {
     var nc = new NullableConverter(_property.PropertyType);
     try
     {
         lock (_setValueLock)
         {
             _property.SetValue(options, nc.ConvertFromString(null, Thread.CurrentThread.CurrentCulture, value), null);
         }
     }
     // the FormatException (thrown by ConvertFromString) is thrown as Exception.InnerException,
     // so we've catch directly System.Exception
     catch (Exception)
     {
         return false;
     }
     return true;
 }
Beispiel #5
0
 public static DateTime?ToDateTime(object obj)
 {
     System.ComponentModel.NullableConverter nullableDateTime = new System.ComponentModel.NullableConverter(typeof(DateTime?));
     return((DateTime?)nullableDateTime.ConvertFromString(obj.ToString()));
 }