public static object ChangeType(Script script, ScriptObject par, Type type) { if (type == TYPE_OBJECT) { return(par.ObjectValue); } else { if (par is ScriptUserdata && Util.IsType(type)) { return(((ScriptUserdata)par).ValueType); } else if (par is ScriptNumber) { return(ChangeType_impl(par.ObjectValue, type)); } else if (Util.IsDelegateType(type)) { if (par is ScriptFunction) { return(script.GetUserdataFactory().GetDelegate(type).Call(new ScriptObject[] { par })); } else { return(par.ObjectValue); } } else { return(par.ObjectValue); } } }
public static bool CanChangeType(ScriptObject par, Type type) { if (type == TYPE_OBJECT || par.IsNull) { return(true); } else { if (par is ScriptString && Util.IsString(type)) { return(true); } else if (par is ScriptNumber && (IsNumber(type) || IsEnum(type))) { return(true); } else if (par is ScriptBoolean && IsBool(type)) { return(true); } else if (par is ScriptEnum && (par as ScriptEnum).EnumType == type) { return(true); } else if (par is ScriptArray && type.IsArray) { return(true); } else if (par is ScriptUserdata) { if (Util.IsType(type)) { return(true); } else if (type.IsAssignableFrom(((ScriptUserdata)par).ValueType)) { return(true); } } else if (type.IsAssignableFrom(par.GetType())) { return(true); } } return(false); }
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); } } }
public static object ChangeType(ScriptObject par, Type type) { if (type == TYPE_OBJECT) { return(par.ObjectValue); } else { if (par is ScriptUserdata && Util.IsType(type)) { return(((ScriptUserdata)par).ValueType); } else if (par is ScriptNumber) { return(ChangeType_impl(par.ObjectValue, type)); } else { return(par.ObjectValue); } } }