本文整理汇总了C#中Jint.Native.JsValue类的典型用法代码示例。如果您正苦于以下问题:C# JsValue类的具体用法?C# JsValue怎么用?C# JsValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsValue类属于Jint.Native命名空间,在下文中一共展示了JsValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ProcessParamsArrays
private JsValue[] ProcessParamsArrays(JsValue[] jsArguments, IEnumerable<MethodInfo> methodInfos)
{
foreach (var methodInfo in methodInfos)
{
var parameters = methodInfo.GetParameters();
if (!parameters.Any(p => Attribute.IsDefined(p, typeof(ParamArrayAttribute))))
continue;
var nonParamsArgumentsCount = parameters.Length - 1;
if (jsArguments.Length < nonParamsArgumentsCount)
continue;
var newArgumentsCollection = jsArguments.Take(nonParamsArgumentsCount).ToList();
var argsToTransform = jsArguments.Skip(nonParamsArgumentsCount).ToList();
if (argsToTransform.Count == 1 && argsToTransform.FirstOrDefault().IsArray())
continue;
var jsArray = Engine.Array.Construct(Arguments.Empty);
Engine.Array.PrototypeObject.Push(jsArray, argsToTransform.ToArray());
newArgumentsCollection.Add(new JsValue(jsArray));
return newArgumentsCollection.ToArray();
}
return jsArguments;
}
开发者ID:icesun963,项目名称:jint,代码行数:27,代码来源:MethodInfoFunctionInstance.cs
示例2: Call5
public string Call5(Delegate callback)
{
var thisArg = JsValue.Undefined;
var arguments = new JsValue[] { 1, "foo" };
return callback.DynamicInvoke(thisArg, arguments).ToString();
}
开发者ID:Willy-Kimura,项目名称:jint,代码行数:7,代码来源:A.cs
示例3: ConvertBack
internal JToken ConvertBack(JsValue value)
{
switch (value.Type)
{
case Jint.Runtime.Types.None:
throw new NotSupportedException();
case Jint.Runtime.Types.Undefined:
return JValue.CreateUndefined();
case Jint.Runtime.Types.Null:
return JValue.CreateNull();
case Jint.Runtime.Types.Boolean:
return new JValue(value.AsBoolean());
case Jint.Runtime.Types.String:
return JValue.CreateString(value.AsString());
case Jint.Runtime.Types.Number:
return new JValue(value.AsNumber());
case Jint.Runtime.Types.Object:
var ntsObjectInstance = value.AsObject() as NTSObjectInstance;
if (ntsObjectInstance != null)
return ntsObjectInstance.root;
return new JObject(value.AsObject().Properties.Where(kvp => !kvp.Value.Enumerable.HasValue || kvp.Value.Enumerable.Value).Select(kvp => new JProperty(kvp.Key, ConvertBack(kvp.Value.Value ?? JsValue.Undefined))));
default:
throw new NotSupportedException();
}
}
开发者ID:npenin,项目名称:jint-newtonsoft.json,代码行数:25,代码来源:NTSObjectInstance.cs
示例4: Call6
public string Call6(Func<JsValue, JsValue[], JsValue> callback)
{
var thisArg = new JsValue("bar");
var arguments = new JsValue[] { 1, "foo" };
return callback(thisArg, arguments).ToString();
}
开发者ID:Willy-Kimura,项目名称:jint,代码行数:7,代码来源:A.cs
示例5: ToRavenJObject
public RavenJObject ToRavenJObject(JsValue jsObject, string propertyKey = null, bool recursiveCall = false)
{
var objectInstance = jsObject.AsObject();
if (objectInstance.Class == "Function")
{
// getting a Function instance here,
// means that we couldn't evaulate it using Jint
return null;
}
var rjo = new RavenJObject();
foreach (var property in objectInstance.Properties)
{
if (property.Key == Constants.ReduceKeyFieldName || property.Key == Constants.DocumentIdFieldName)
continue;
var value = property.Value.Value;
if (value.HasValue == false)
continue;
if (value.Value.IsRegExp())
continue;
var recursive = jsObject == value;
if (recursiveCall && recursive)
rjo[property.Key] = null;
else
rjo[property.Key] = ToRavenJToken(value.Value, CreatePropertyKey(property.Key, propertyKey), recursive);
}
return rjo;
}
开发者ID:j2jensen,项目名称:ravendb,代码行数:31,代码来源:JintOperationScope.cs
示例6: Put
public override void Put(string propertyName, JsValue value, bool throwOnError)
{
if (!CanPut(propertyName))
{
if (throwOnError)
{
throw new JavaScriptException(Engine.TypeError);
}
return;
}
var ownDesc = GetOwnProperty(propertyName);
if (ownDesc == null)
{
if (throwOnError)
{
throw new JavaScriptException(Engine.TypeError, "Unknown member: " + propertyName);
}
else
{
return;
}
}
ownDesc.Value = value;
}
开发者ID:icesun963,项目名称:jint,代码行数:28,代码来源:ObjectWrapper.cs
示例7: Call
public JsValue Call(JsValue thisObject, JsValue[] arguments)
{
// direct calls on a NamespaceReference constructor object is creating a generic type
var genericTypes = new Type[arguments.Length];
for (int i = 0; i < arguments.Length; i++)
{
var genericTypeReference = arguments.At(i);
if (genericTypeReference == Undefined.Instance || !genericTypeReference.IsObject() || genericTypeReference.AsObject().Class != "TypeReference")
{
throw new JavaScriptException(Engine.TypeError, "Invalid generic type parameter");
}
genericTypes[i] = arguments.At(0).As<TypeReference>().Type;
}
var typeReference = GetPath(_path + "`" + arguments.Length.ToString(CultureInfo.InvariantCulture)).As<TypeReference>();
if (typeReference == null)
{
return Undefined.Instance;
}
var genericType = typeReference.Type.MakeGenericType(genericTypes);
return TypeReference.CreateTypeReference(Engine, genericType);
}
开发者ID:postromantic,项目名称:jint,代码行数:26,代码来源:NamespaceReference.cs
示例8: ToOptionalInt32
public static Nullable<Int32> ToOptionalInt32(JsValue arg)
{
if (arg.IsNumber())
return TypeConverter.ToInt32(arg);
return null;
}
开发者ID:AlgorithmsAreCool,项目名称:AngleSharp.Scripting,代码行数:7,代码来源:SystemTypeConverter.cs
示例9: CheckObjectCoercible
public static void CheckObjectCoercible(Engine engine, JsValue o)
{
if (o == Undefined.Instance || o == Null.Instance)
{
throw new JavaScriptException(engine.TypeError);
}
}
开发者ID:ImagineLearning,项目名称:Jint,代码行数:7,代码来源:TypeConverter.cs
示例10: Compare
public static JsValue Compare(JsValue x, JsValue y, bool leftFirst = true)
{
JsValue px, py;
if (leftFirst)
{
px = TypeConverter.ToPrimitive(x, Types.Number);
py = TypeConverter.ToPrimitive(y, Types.Number);
}
else
{
py = TypeConverter.ToPrimitive(y, Types.Number);
px = TypeConverter.ToPrimitive(x, Types.Number);
}
var typea = px.Type;
var typeb = py.Type;
if (typea != Types.String || typeb != Types.String)
{
var nx = TypeConverter.ToNumber(px);
var ny = TypeConverter.ToNumber(py);
if (double.IsNaN(nx) || double.IsNaN(ny))
{
return Undefined.Instance;
}
if (nx.Equals(ny))
{
return false;
}
if (double.IsPositiveInfinity(nx))
{
return false;
}
if (double.IsPositiveInfinity(ny))
{
return true;
}
if (double.IsNegativeInfinity(ny))
{
return false;
}
if (double.IsNegativeInfinity(nx))
{
return true;
}
return nx < ny;
}
else
{
return String.CompareOrdinal(TypeConverter.ToString(x), TypeConverter.ToString(y)) < 0;
}
}
开发者ID:honestegg,项目名称:jint,代码行数:59,代码来源:ExpressionIntepreter.cs
示例11: 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);
}
开发者ID:AlgorithmsAreCool,项目名称:AngleSharp.Scripting,代码行数:10,代码来源:DomFunctionInstance.cs
示例12: Log
JsValue Log(JsValue ctx, JsValue[] args)
{
var strs = new String[args.Length];
for (var i = 0; i < args.Length; i++)
strs[i] = args[i].ToString();
Console.WriteLine(String.Join(", ", strs));
return JsValue.Undefined;
}
开发者ID:AlgorithmsAreCool,项目名称:AngleSharp.Scripting,代码行数:10,代码来源:ConsoleInstance.cs
示例13: TryConvert
public bool TryConvert(object value, out JsValue result)
{
if (value is bool)
{
result = !(bool) value;
return true;
}
result = JsValue.Null;
return false;
}
开发者ID:BusinessActs,项目名称:jint,代码行数:11,代码来源:NegateBoolConverter.cs
示例14: TryConvert
public bool TryConvert(object value, out JsValue result)
{
if (value is Enum)
{
result = value.ToString();
return true;
}
result = JsValue.Null;
return false;
}
开发者ID:honestegg,项目名称:jint,代码行数:11,代码来源:EnumsToStringConverter.cs
示例15: GetErrorMessage
private static string GetErrorMessage(JsValue error)
{
if (error.IsObject())
{
var oi = error.AsObject();
var message = oi.Get("message").AsString();
return message;
}
else
return string.Empty;
}
开发者ID:Willy-Kimura,项目名称:jint,代码行数:11,代码来源:JavaScriptException.cs
示例16: ToObjBag
public static IDictionary<String, Object> ToObjBag(JsValue arg)
{
var obj = arg.AsObject();
var dict = new Dictionary<String, Object>();
var properties = obj.GetOwnProperties();
foreach (var property in properties)
dict.Add(property.Key, property.Value.Value.Clr());
return dict;
}
开发者ID:AlgorithmsAreCool,项目名称:AngleSharp.Scripting,代码行数:11,代码来源:SystemTypeConverter.cs
示例17: Call
public override JsValue Call(JsValue thisObject, JsValue[] arguments)
{
try
{
var result = _func(thisObject, arguments);
return result;
}
catch (InvalidCastException)
{
throw new JavaScriptException(Engine.TypeError);
}
}
开发者ID:Willy-Kimura,项目名称:jint,代码行数:12,代码来源:ClrFunctionInstance.cs
示例18: Construct
public ObjectInstance Construct(JsValue[] arguments)
{
if (arguments.Length == 0 && Type.IsValueType())
{
var instance = Activator.CreateInstance(Type);
var result = TypeConverter.ToObject(Engine, JsValue.FromObject(Engine, instance));
return result;
}
var constructors = Type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
var methods = TypeConverter.FindBestMatch(Engine, constructors, arguments).ToList();
foreach (var method in methods)
{
var parameters = new object[arguments.Length];
try
{
for (var i = 0; i < arguments.Length; i++)
{
var parameterType = method.GetParameters()[i].ParameterType;
if (parameterType == typeof(JsValue))
{
parameters[i] = arguments[i];
}
else
{
parameters[i] = Engine.ClrTypeConverter.Convert(
arguments[i].ToObject(),
parameterType,
CultureInfo.InvariantCulture);
}
}
var constructor = (ConstructorInfo)method;
var instance = constructor.Invoke(parameters.ToArray());
var result = TypeConverter.ToObject(Engine, JsValue.FromObject(Engine, instance));
// todo: cache method info
return result;
}
catch
{
// ignore method
}
}
throw new JavaScriptException(Engine.TypeError, "No public methods with the specified arguments were found.");
}
开发者ID:textmetal,项目名称:main,代码行数:53,代码来源:TypeReference.cs
示例19: ToPrimitive
/// <summary>
/// http://www.ecma-international.org/ecma-262/5.1/#sec-9.1
/// </summary>
/// <param name="input"></param>
/// <param name="preferredType"></param>
/// <returns></returns>
public static JsValue ToPrimitive(JsValue input, Types preferredType = Types.None)
{
if (input == Null.Instance || input == Undefined.Instance)
{
return input;
}
if (input.IsPrimitive())
{
return input;
}
return input.AsObject().DefaultValue(preferredType);
}
开发者ID:Harllens,项目名称:jint,代码行数:20,代码来源:TypeConverter.cs
示例20: FindBestMatch
public static IEnumerable<MethodBase> FindBestMatch(Engine engine, MethodBase[] methods, JsValue[] arguments)
{
methods = methods
.Where(m => m.GetParameters().Count() == arguments.Length ||
(m.IsGenericMethodDefinition && m.GetGenericArguments().Count() == arguments.Length))
.ToArray();
if (methods.Length == 1 && !methods[0].GetParameters().Any())
{
yield return methods[0];
yield break;
}
var objectArguments = arguments.Select(x => x.ToObject()).ToArray();
foreach (var method in methods)
{
var perfectMatch = true;
var parameters = method.GetParameters();
for (var i = 0; i < arguments.Length; i++)
{
var arg = objectArguments[i];
var paramType = parameters[i].ParameterType;
if (arg == null)
{
if (!TypeIsNullable(paramType))
{
perfectMatch = false;
break;
}
}
else if (arg.GetType() != paramType)
{
perfectMatch = false;
break;
}
}
if (perfectMatch)
{
yield return method;
yield break;
}
}
foreach (var method in methods)
{
yield return method;
}
}
开发者ID:ImagineLearning,项目名称:Jint,代码行数:50,代码来源:TypeConverter.cs
注:本文中的Jint.Native.JsValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论