本文整理汇总了C#中Jint.Native.JsValue.TryCast方法的典型用法代码示例。如果您正苦于以下问题:C# JsValue.TryCast方法的具体用法?C# JsValue.TryCast怎么用?C# JsValue.TryCast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Native.JsValue
的用法示例。
在下文中一共展示了JsValue.TryCast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString
private JsValue ToString(JsValue thisObj, JsValue[] arguments)
{
var func = thisObj.TryCast<FunctionInstance>();
if (func == null)
throw new JavaScriptException(Engine.TypeError, "Function object expected.");
var officialName = _method.GetOfficialName();
return string.Format("function {0} () {{ [native code] }}", officialName);
}
示例2: ToPropertyDescriptor
public static PropertyDescriptor ToPropertyDescriptor(Engine engine, JsValue o)
{
var obj = o.TryCast<ObjectInstance>();
if (obj == null)
{
throw new JavaScriptException(engine.TypeError);
}
if ((obj.HasProperty("value") || obj.HasProperty("writable")) &&
(obj.HasProperty("get") || obj.HasProperty("set")))
{
throw new JavaScriptException(engine.TypeError);
}
var desc = new PropertyDescriptor();
if (obj.HasProperty("enumerable"))
{
desc.Enumerable = TypeConverter.ToBoolean(obj.Get("enumerable"));
}
if (obj.HasProperty("configurable"))
{
desc.Configurable = TypeConverter.ToBoolean(obj.Get("configurable"));
}
if (obj.HasProperty("value"))
{
var value = obj.Get("value");
desc.Value = value;
}
if (obj.HasProperty("writable"))
{
desc.Writable = TypeConverter.ToBoolean(obj.Get("writable"));
}
if (obj.HasProperty("get"))
{
var getter = obj.Get("get");
if (getter != JsValue.Undefined && getter.TryCast<ICallable>() == null)
{
throw new JavaScriptException(engine.TypeError);
}
desc.Get = getter;
}
if (obj.HasProperty("set"))
{
var setter = obj.Get("set");
if (setter != Native.Undefined.Instance && setter.TryCast<ICallable>() == null)
{
throw new JavaScriptException(engine.TypeError);
}
desc.Set = setter;
}
if (desc.Get.HasValue || desc.Get.HasValue)
{
if (desc.Value.HasValue || desc.Writable.HasValue)
{
throw new JavaScriptException(engine.TypeError);
}
}
return desc;
}
示例3: GetPrimitiveType
public static Types GetPrimitiveType(JsValue value)
{
if (value.IsObject())
{
var primitive = value.TryCast<IPrimitiveInstance>();
if (primitive != null)
{
return primitive.Type;
}
return Types.Object;
}
return value.Type;
}
示例4: Invoke
/// <summary>
/// Invoke the current value as function.
/// </summary>
/// <param name="value">The function to call.</param>
/// <param name="thisObj">The this value inside the function call.</param>
/// <param name="arguments">The arguments of the function call.</param>
/// <returns>The value returned by the function call.</returns>
public JsValue Invoke(JsValue value, object thisObj, object[] arguments)
{
var callable = value.TryCast<ICallable>();
if (callable == null)
{
throw new ArgumentException("Can only invoke functions");
}
return callable.Call(JsValue.FromObject(this, thisObj), arguments.Select(x => JsValue.FromObject(this, x)).ToArray());
}