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


C# ScriptProcessor.CreateArray方法代码示例

本文整理汇总了C#中ScriptProcessor.CreateArray方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptProcessor.CreateArray方法的具体用法?C# ScriptProcessor.CreateArray怎么用?C# ScriptProcessor.CreateArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptProcessor的用法示例。


在下文中一共展示了ScriptProcessor.CreateArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        /// <summary>
        /// Parses a string as an array.
        /// </summary>
        internal new static SObject Parse(ScriptProcessor processor, string exp)
        {
            // Format: [item1, item2, ... itemn]

            if (Regex.IsMatch(exp, REGEX_EMPTY_ARRAY)) return processor.CreateArray(0);

            exp = exp.Remove(exp.Length - 1, 1).Remove(0, 1).Trim(); // Remove [ and ].

            var elements = new List<SObject>();

            var elementStart = 0;
            var index = 0;
            var depth = 0;
            StringEscapeHelper escaper = new LeftToRightStringEscapeHelper(exp, 0);
            string element;

            while (index < exp.Length)
            {
                var t = exp[index];
                escaper.CheckStartAt(index);

                if (!escaper.IsString)
                {
                    if (t == '{' || t == '[' || t == '(')
                    {
                        depth++;
                    }
                    else if (t == '}' || t == ']' || t == ')')
                    {
                        depth--;
                    }
                    else if (t == ',' && depth == 0)
                    {
                        element = exp.Substring(elementStart, index - elementStart);
                        
                        if (string.IsNullOrWhiteSpace(element))
                            elements.Add(processor.Undefined);
                        else
                            elements.Add(processor.ExecuteStatement(new ScriptStatement(element)));

                        elementStart = index + 1;
                    }
                }

                index++;
            }

            element = exp.Substring(elementStart, index - elementStart);

            if (string.IsNullOrWhiteSpace(element))
                elements.Add(processor.Undefined);
            else
                elements.Add(processor.ExecuteStatement(new ScriptStatement(element)));

            return processor.CreateArray(elements.ToArray());
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:59,代码来源:SArray.cs

示例2: Split

        public static SObject Split(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            int limit = -1;
            string[] split;
            string[] delimiters;
            string str = (instance as SString).Value;

            if (TypeContract.Ensure(parameters, new[] { typeof(SArray), typeof(SNumber) }))
            {
                delimiters = (parameters[0] as SArray).ArrayMembers.Select(m => m.ToString(processor).Value).ToArray();
                limit = (int)(parameters[1] as SNumber).Value;
            }
            else if (TypeContract.Ensure(parameters, typeof(SArray)))
            {
                delimiters = (parameters[0] as SArray).ArrayMembers.Select(m => m.ToString(processor).Value).ToArray();
            }
            else if (TypeContract.Ensure(parameters, new[] { typeof(SString), typeof(SNumber) }))
            {
                delimiters = new[] { (parameters[0] as SString).Value };
                limit = (int)(parameters[1] as SNumber).Value;
            }
            else if (TypeContract.Ensure(parameters, typeof(SString)))
            {
                delimiters = new[] { (parameters[0] as SString).Value };
            }
            else
            {
                return processor.CreateArray(new[] { processor.CreateString(str) });
            }

            split = str.Split(delimiters, StringSplitOptions.None);
            if (limit >= 0 && split.Length > limit)
            {
                var result = new string[limit];
                Array.Copy(split, result, limit);
                split = result;
            }

            return processor.CreateArray(split.Select(m => processor.CreateString(m)).ToArray());
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:40,代码来源:StringPrototype.cs

示例3: TranslateArray

 private static SObject TranslateArray(ScriptProcessor processor, Array array) =>
     processor.CreateArray(array.Cast<object>().Select((t, i) =>
             Translate(processor, array.GetValue(i))).ToArray());
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:3,代码来源:ScriptInAdapter.cs

示例4: Select

        public static SObject Select(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length >= 1)
            {
                var arr = (SArray)instance;
                var comparer = (SFunction)Unbox(parameters[0]);

                var result = arr.ArrayMembers.Select(m => comparer.Call(processor, This, This, new[] { m }));
                return processor.CreateArray(result.ToArray());
            }

            return processor.Undefined;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:13,代码来源:ArrayPrototype.cs

示例5: Where

        public static SObject Where(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length >= 1)
            {
                var arr = (SArray)instance;
                var comparer = (SFunction)Unbox(parameters[0]);

                var results = arr.ArrayMembers.Where((m, i) => ((SBool)comparer.Call(processor, This, This, new[] {m, processor.CreateNumber(i)})).Value);
                return processor.CreateArray(results.ToArray());
            }

            return processor.Undefined;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:13,代码来源:ArrayPrototype.cs


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