using Serein.Library;
using Serein.Library.Utils;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Serein.Library
{
///
/// 脚本代码中常用的函数
///
public static class ScriptBaseFunc
{
///
/// 获取当前时间
///
///
public static DateTime now() => DateTime.Now;
#region 常用的类型转换
///
/// 将值转换为bool类型
///
///
///
public static bool @bool(object value)
{
return ConvertHelper.ValueParse(value);
}
///
/// 将值转换为字节类型
///
///
///
public static byte @byte(object value)
{
return ConvertHelper.ValueParse(value);
}
///
/// 将值转换为短整型
///
///
///
public static decimal @decimal(object value)
{
return ConvertHelper.ValueParse(value);
}
///
/// 将值转换为浮点型
///
///
///
public static float @float(object value)
{
return ConvertHelper.ValueParse(value);
}
///
/// 将值转换为双精度浮点型
///
///
///
public static double @double(object value)
{
return ConvertHelper.ValueParse(value);
}
///
/// 将值转换为整数类型
///
///
///
public static int @int(object value)
{
return ConvertHelper.ValueParse(value);
}
///
/// 将值转换为长整型
///
///
///
public static int @long(object value)
{
return ConvertHelper.ValueParse(value);
}
#endregion
///
/// 获取集合或数组的长度
///
///
///
///
public static int len(object target)
{
// 获取数组或集合对象
// 访问数组或集合中的指定索引
if (target is Array array)
{
return array.Length;
}
else if (target is string chars)
{
return chars.Length;
}
else if (target is IDictionary