Пример #1
0
 public static object ChangeType(ScriptObject par, Type type)
 {
     if (type == TYPE_OBJECT)
     {
         if (par is ScriptNumber)
         {
             return(ChangeType_impl(par.ObjectValue, type));
         }
         else
         {
             return(par.ObjectValue);
         }
     }
     else
     {
         if (type.IsAssignableFrom(par.GetType()))
         {
             return(par);
         }
         else if (par is ScriptNumber)
         {
             return(Util.IsEnum(type) ? ToEnum(type, ((ScriptNumber)par).ToLong()) : ChangeType_impl(par.ObjectValue, type));
         }
         else if (par is ScriptArray)
         {
             return(ChangeType_impl(par as ScriptArray, type));
         }
         else if (par is ScriptUserdata)
         {
             if (Util.IsType(type))
             {
                 return(((ScriptUserdata)par).ValueType);
             }
             else
             {
                 return(par.ObjectValue);
             }
         }
         else
         {
             return(par.ObjectValue);
         }
     }
 }