Esempio n. 1
0
 public object Convert(object val, Type type)
 {
     using (var context = new ConvertContext())
     {
         bool b;
         var  obj = Convertor.ChangeType(context, val, type, out b);
         if (b == false)
         {
             context.ThrowIfHaveError();
         }
         return(obj);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 将值转换为给定的 <see cref="T:System.Type" />。
 /// </summary>
 /// <returns> 转换后的 <paramref name="value" />。 </returns>
 /// <param name="value"> 要转换的对象。 </param>
 public override T Convert <T>(object value)
 {
     using (var context = new ConvertContext())
     {
         bool b;
         var  output = Convertor.ChangeType(context, value, typeof(T), out b);
         if (_throwError && (b == false))
         {
             context.ThrowIfHaveError();
         }
         return((T)output);
     }
 }