本文整理汇总了C#中Jint.Native.JsInstance.ToPrimitive方法的典型用法代码示例。如果您正苦于以下问题:C# JsInstance.ToPrimitive方法的具体用法?C# JsInstance.ToPrimitive怎么用?C# JsInstance.ToPrimitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Native.JsInstance
的用法示例。
在下文中一共展示了JsInstance.ToPrimitive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
public JsBoolean Compare(JsInstance x, JsInstance y)
{
if (x.IsClr && y.IsClr)
{
return Global.BooleanClass.New(x.Value.Equals(y.Value));
}
if (x.IsClr)
{
return Compare(x.ToPrimitive(Global), y);
}
if (y.IsClr)
{
return Compare(x, y.ToPrimitive(Global));
}
if (x.Type == y.Type)
{ // if both are Objects but then only one is Clrs
if (x == JsUndefined.Instance)
{
return Global.BooleanClass.True;
}
else if (x == JsNull.Instance)
{
return Global.BooleanClass.True;
}
else if (x.Type == JsInstance.TYPE_NUMBER)
{
if (x.ToNumber() == double.NaN)
{
return Global.BooleanClass.False;
}
else if (y.ToNumber() == double.NaN)
{
return Global.BooleanClass.False;
}
else if (x.ToNumber() == y.ToNumber())
{
return Global.BooleanClass.True;
}
else
{
return Global.BooleanClass.False;
}
}
else if (x.Type == JsInstance.TYPE_STRING)
{
return Global.BooleanClass.New(x.ToString() == y.ToString());
}
else if (x.Type == JsInstance.TYPE_BOOLEAN)
{
return Global.BooleanClass.New(x.ToBoolean() == y.ToBoolean());
}
else if (x.Type == JsInstance.TYPE_OBJECT )
{
return Global.BooleanClass.New(x == y);
}
else
{
return Global.BooleanClass.New(x.Value.Equals(y.Value));
}
}
else if (x == JsNull.Instance && y == JsUndefined.Instance)
{
return Global.BooleanClass.True;
}
else if (x == JsUndefined.Instance && y == JsNull.Instance)
{
return Global.BooleanClass.True;
}
else if (x.Type == JsInstance.TYPE_NUMBER && y.Type == JsInstance.TYPE_STRING)
{
return Global.BooleanClass.New(x.ToNumber() == y.ToNumber());
}
else if (x.Type == JsInstance.TYPE_STRING && y.Type == JsInstance.TYPE_NUMBER)
{
return Global.BooleanClass.New(x.ToNumber() == y.ToNumber());
}
else if (x.Type == JsInstance.TYPE_BOOLEAN || y.Type == JsInstance.TYPE_BOOLEAN)
{
return Global.BooleanClass.New(x.ToNumber() == y.ToNumber());
}
else if (y.Type == JsInstance.TYPE_OBJECT && (x.Type == JsInstance.TYPE_STRING || x.Type == JsInstance.TYPE_NUMBER))
{
return Compare(x, y.ToPrimitive(Global));
}
else if (x.Type == JsInstance.TYPE_OBJECT && (y.Type == JsInstance.TYPE_STRING || y.Type == JsInstance.TYPE_NUMBER))
{
return Compare(x.ToPrimitive(Global), y);
}
else
{
return Global.BooleanClass.False;
}
}