Skip to content

Commit 80b01c5

Browse files
committed
рефакторинг: поле вместо свойства, уточнение типа, чистка локальных
1 parent 9e820b5 commit 80b01c5

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTableRow.cs

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace OneScript.StandardLibrary.Collections.ValueTable
1616
[ContextClass("СтрокаТаблицыЗначений", "ValueTableRow")]
1717
public class ValueTableRow : AutoContext<ValueTableRow>, ICollectionContext<IValue>, IDebugPresentationAcceptor
1818
{
19-
private readonly Dictionary<IValue, IValue> _data = new Dictionary<IValue, IValue>();
19+
private readonly Dictionary<ValueTableColumn, IValue> _data = new Dictionary<ValueTableColumn, IValue>();
2020
private readonly ValueTable _owner;
2121

2222
public ValueTableRow(ValueTable owner)
@@ -26,7 +26,7 @@ public ValueTableRow(ValueTable owner)
2626

2727
public int Count()
2828
{
29-
return Owner().Columns.Count();
29+
return _owner.Columns.Count();
3030
}
3131

3232
public int Count(IBslProcess process) => Count();
@@ -43,12 +43,11 @@ public ValueTable Owner()
4343

4444
private IValue TryValue(ValueTableColumn Column)
4545
{
46-
IValue Value;
47-
if (_data.TryGetValue(Column, out Value))
48-
{
49-
return Value;
50-
}
51-
return Column.ValueType.AdjustValue();
46+
if (_data.TryGetValue(Column, out IValue Value))
47+
{
48+
return Value;
49+
}
50+
return Column.ValueType.AdjustValue();
5251
}
5352

5453
/// <summary>
@@ -59,19 +58,17 @@ private IValue TryValue(ValueTableColumn Column)
5958
[ContextMethod("Получить", "Get")]
6059
public IValue Get(int index)
6160
{
62-
var C = Owner().Columns.FindColumnByIndex(index);
63-
return TryValue(C);
61+
return TryValue(_owner.Columns.FindColumnByIndex(index));
6462
}
6563

6664
public IValue Get(IValue index)
6765
{
68-
var C = Owner().Columns.GetColumnByIIndex(index);
69-
return TryValue(C);
66+
return TryValue(_owner.Columns.GetColumnByIIndex(index));
7067
}
7168

72-
public IValue Get(ValueTableColumn c)
69+
public IValue Get(ValueTableColumn column)
7370
{
74-
return TryValue(c);
71+
return TryValue(column);
7572
}
7673

7774
/// <summary>
@@ -82,31 +79,29 @@ public IValue Get(ValueTableColumn c)
8279
[ContextMethod("Установить", "Set")]
8380
public void Set(int index, IValue value)
8481
{
85-
var C = Owner().Columns.FindColumnByIndex(index);
86-
Set(C, value);
82+
Set(_owner.Columns.FindColumnByIndex(index), value);
8783
}
8884

8985
public void Set(IValue index, IValue value)
9086
{
91-
var C = Owner().Columns.GetColumnByIIndex(index);
92-
Set(C, value);
87+
Set(_owner.Columns.GetColumnByIIndex(index), value);
9388
}
9489

9590
public void Set(ValueTableColumn column, IValue value)
9691
{
97-
Owner().Indexes.ElementRemoved(this);
92+
_owner.Indexes.ElementRemoved(this);
9893
_data[column] = column.ValueType.AdjustValue(value);
99-
Owner().Indexes.ElementAdded(this);
94+
_owner.Indexes.ElementAdded(this);
10095
}
10196

102-
public void OnOwnerColumnRemoval(IValue column)
97+
public void OnOwnerColumnRemoval(ValueTableColumn column)
10398
{
10499
_data.Remove(column);
105100
}
106101

107102
public IEnumerator<IValue> GetEnumerator()
108103
{
109-
foreach (var item in Owner().Columns)
104+
foreach (var item in _owner.Columns)
110105
{
111106
yield return TryValue(item);
112107
}
@@ -124,45 +119,36 @@ public override int GetPropCount()
124119

125120
public override string GetPropName(int propNum)
126121
{
127-
return Owner().Columns.GetPropName(propNum);
122+
return _owner.Columns.GetPropName(propNum);
128123
}
129124

130125
public override int GetPropertyNumber(string name)
131126
{
132-
return Owner().Columns.GetPropertyNumber(name);
127+
return _owner.Columns.GetPropertyNumber(name);
133128
}
134129

135-
public override bool IsPropReadable(int propNum)
136-
{
137-
return true;
138-
}
130+
public override bool IsPropReadable(int propNum) => true;
139131

140-
public override bool IsPropWritable(int propNum)
141-
{
142-
return true;
143-
}
132+
public override bool IsPropWritable(int propNum) => true;
144133

145134
public override IValue GetPropValue(int propNum)
146135
{
147-
var C = Owner().Columns.FindColumnByIndex(propNum);
148-
return TryValue(C);
136+
return TryValue(_owner.Columns.FindColumnByIndex(propNum));
149137
}
150138

151139
public override void SetPropValue(int propNum, IValue newVal)
152140
{
153-
var C = Owner().Columns.FindColumnByIndex(propNum);
154-
Set(C, newVal);
141+
Set(_owner.Columns.FindColumnByIndex(propNum), newVal);
155142
}
156143

157144
private ValueTableColumn GetColumnByIIndex(IValue index)
158145
{
159-
return Owner().Columns.GetColumnByIIndex(index);
146+
return _owner.Columns.GetColumnByIIndex(index);
160147
}
161148

162149
public override IValue GetIndexedValue(IValue index)
163150
{
164-
ValueTableColumn C = GetColumnByIIndex(index);
165-
return TryValue(C);
151+
return TryValue(GetColumnByIIndex(index));
166152
}
167153

168154
public override void SetIndexedValue(IValue index, IValue val)

0 commit comments

Comments
 (0)