Ejemplo n.º 1
0
 public object ConvertType(object o, Type type, string tname, string method)
 {
     if (type.IsInstanceOfType(o)) return o;
     object result = null;
     try
     {
         result = Funcall(o, method, null);
     }
     catch (Exception e)
     {
         string s;
         if (o == null) s = "nil";
         else if (o is bool)
             s = ((bool)o) ? "true" : "false";
         else
             s = ClassOf(o).ClassName;
         eTypeError ex = new eTypeError(String.Format("failed to convert {0} into {1}",
                                                      s, tname), e);
         throw ex;
     }
     if (result is int
         && (type == typeof(RInteger) || type == typeof(RFixnum)))
     {
         return new RFixnum(this, (int)result);
     }
     if (result is long
         && (type == typeof(RInteger) || type == typeof(RBignum)))
     {
         return new RBignum(this, (long)result);
     }
     if (type.IsInstanceOfType(result) == false)
     {
         eTypeError ex = new eTypeError(String.Format("{0}#{1} should return {2}",
                                                      ClassOf(o).ClassName,
                                                      method, tname));
         throw ex;
     }
     return result;
 }
Ejemplo n.º 2
0
 public object CheckConvertType(object o, Type type, string tname, string method)
 {
     if (type.IsInstanceOfType(o)) return o;
     object result = null;
     try
     {
         result = Funcall(o, method, null);
     }
     catch
     {
         ;
     }
     if (type == typeof(RInteger))
     {
         if (result is int)
             return new RFixnum(this, (int)result);
         else if (result is long)
             return new RBignum(this, (long)result);
     }
     if (result != null && type.IsInstanceOfType(result) == false)
     {
         eTypeError ex = new eTypeError(String.Format("{0}#{1} should return {2}",
                                                      ClassOf(o).ClassName,
                                                      method, tname));
         throw ex;
     }
     return result;
 }