当前位置: 首页>>代码示例>>C#>>正文


C# Native.JsValue类代码示例

本文整理汇总了C#中Jint.Native.JsValue的典型用法代码示例。如果您正苦于以下问题:C# JsValue类的具体用法?C# JsValue怎么用?C# JsValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsValue类属于Jint.Native命名空间,在下文中一共展示了JsValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的Jint.Native.JsValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。