本文整理汇总了C#中Jint.Native.JsInstance.ToObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsInstance.ToObject方法的具体用法?C# JsInstance.ToObject怎么用?C# JsInstance.ToObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Native.JsInstance
的用法示例。
在下文中一共展示了JsInstance.ToObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseDate
static DateTime ParseDate(JsInstance obj)
{
DateTime result;
if (!TryParseDate(obj, out result))
throw new JsGlobalException(
"Invalid cast '{0}' to 'DateTime'. Js object: {1}".Formatting(obj.ToObject(), obj));
return result;
}
示例2: TryParseDate
static bool TryParseDate(JsInstance arg, out DateTime result)
{
object obj = arg.ToObject();
string input = obj as string;
if (input != null)
{
if (!DateTime.TryParse(input, out result))
if (!DateTime.TryParse(input, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
if (!DateTime.TryParseExact(input, "yyyyMMddHHmmss", CultureInfo.CurrentCulture, DateTimeStyles.None, out result))
if (!DateTime.TryParseExact(input, "yyyyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out result))
return false;
return true;
}
else if (obj is DateTime)
{
result = (DateTime)obj;
return true;
}
result = DateTime.MinValue;
return false;
}
示例3: TryParseNum
static bool TryParseNum(JsInstance arg, out double result)
{
object obj = arg.ToObject();
if (obj is string)
{
var input = (string)obj;
if (input.Trim() == "-" || input.Trim() == ".")
{
result = 0;
return true;
}
if (!double.TryParse(input, out result))
if (!double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
return false;
return true;
}
if (obj is bool)
{
result = (bool)obj ? 1 : 0;
return true;
}
try
{
result = (double)Convert.ChangeType(obj, typeof(double));
return true;
}
catch (InvalidCastException)
{
result = double.NaN;
return false;
}
}
示例4: ParseDouble
static double ParseDouble(JsInstance obj)
{
double result;
if (!TryParseNum(obj, out result))
throw new JsGlobalException(
"Invalid cast '{0}' to 'Int'. Js object: {1}".Formatting(obj.ToObject(), obj));
if (double.IsNaN(result) || double.IsInfinity(result))
throw new JsGlobalException("Argument is NaN or Infinity");
return result;
}
示例5: ParseInt
static int ParseInt(JsInstance obj)
{
double result;
if (!TryParseNum(obj, out result))
throw new JsGlobalException(
"Invalid cast '{0}' to 'Int'. Js object: {1}".Formatting(obj.ToObject(), obj));
return (int)result;
}
示例6: TryParseString
static bool TryParseString(JsInstance obj, out string result)
{
result = obj.ToObject() as string;
return result != null;
}
示例7: TryParseBool
static bool TryParseBool(JsInstance arg, out bool result)
{
object obj = arg.ToObject();
if (obj is string)
{
string input = (string)obj;
if (!bool.TryParse(input, out result))
return false;
}
else if (obj is bool)
{
result = (bool)obj;
}
else
{
double input = ParseDouble(arg);
if (input < 0)
{
result = false;
return false;
}
result = input != 0;
}
return true;
}