forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringValuesWrapper.cs
More file actions
74 lines (59 loc) · 2.05 KB
/
StringValuesWrapper.cs
File metadata and controls
74 lines (59 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using OneScript.Contexts;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;
using System.Collections.Generic;
using OneScript.Values;
using Microsoft.Extensions.Primitives;
namespace OneScript.Web.Server
{
[ContextClass("СтроковыеЗначения", "StringValues")]
public class StringValuesWrapper : AutoCollectionContext<StringValuesWrapper, IValue>
{
private readonly StringValues _value;
public static implicit operator StringValues(StringValuesWrapper d) => d._value;
public static implicit operator StringValuesWrapper(StringValues b) => new(b);
internal StringValuesWrapper(StringValues value)
{
_value = value;
}
public override bool IsIndexed => true;
public override IValue GetIndexedValue(IValue index)
{
var value = (int)index.AsNumber();
return ValueFactory.Create(_value[value]);
}
#region ICollectionContext Members
[ContextMethod("Получить", "Get")]
public IValue Retrieve(IValue key)
{
return GetIndexedValue(key);
}
[ContextMethod("Количество", "Count")]
public override int Count()
{
return _value.Count;
}
#endregion
#region IEnumerable<IValue> Members
public override IEnumerator<IValue> GetEnumerator()
{
foreach (var item in _value)
yield return BslStringValue.Create(item);
}
#endregion
public override string ToString()
{
return _value.ToString();
}
public override int GetHashCode()
{
return _value.GetHashCode();
}
}
}