本文整理汇总了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());
}
示例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());
}
示例3: TranslateArray
private static SObject TranslateArray(ScriptProcessor processor, Array array) =>
processor.CreateArray(array.Cast<object>().Select((t, i) =>
Translate(processor, array.GetValue(i))).ToArray());
示例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;
}
示例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;
}