Skip to content

Commit 8d40873

Browse files
Merge pull request #18 from SimpleStateMachine/dev
fix ArgumentOutOfRangeException exception
2 parents 1171ebf + 04899f2 commit 8d40873

File tree

15 files changed

+48
-24
lines changed

15 files changed

+48
-24
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Expr.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public double Invoke()
9696
UnaryOperatorType.Decrement => Expr.Invoke() - 1,
9797
UnaryOperatorType.Plus => - Expr.Invoke(),
9898
UnaryOperatorType.Minus => + Expr.Invoke(),
99-
_ => throw new ArgumentOutOfRangeException()
99+
_ => throw new ArgumentOutOfRangeException(nameof(Type), Type, null)
100100
};
101101
}
102102
}
@@ -135,7 +135,7 @@ public double Invoke()
135135
BinaryOperatorType.Mul => Left.Invoke() * Right.Invoke(),
136136
BinaryOperatorType.Div => Left.Invoke() / Right.Invoke(),
137137
BinaryOperatorType.Sub => Left.Invoke() - Right.Invoke(),
138-
_ => throw new ArgumentOutOfRangeException()
138+
_ => throw new ArgumentOutOfRangeException(nameof(Type), Type, null)
139139
};
140140
}
141141
}

src/SimpleStateMachine.StructuralSearch/Helper/LogicalHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace SimpleStateMachine.StructuralSearch.Helper
55
{
6-
public static class LogicalHelper
6+
public static class LogicalHelper
77
{
88
public static bool Calculate(BinaryRuleType type, bool left, bool right)
99
{

src/SimpleStateMachine.StructuralSearch/Helper/MatchHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static ParenthesisType GetParenthesisType((char c1, char c2) parenthesis)
1212
(Constant.LeftParenthesis, Constant.RightParenthesis) => ParenthesisType.Usual,
1313
(Constant.LeftSquareParenthesis, Constant.RightSquareParenthesis) => ParenthesisType.Square,
1414
(Constant.LeftCurlyParenthesis, Constant.RightCurlyParenthesis) => ParenthesisType.Curly,
15-
_ => throw new ArgumentOutOfRangeException()
15+
_ => throw new ArgumentOutOfRangeException(nameof(parenthesis), parenthesis, null)
1616
};
1717

1818
return type;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Linq;
2+
using System.Text;
3+
4+
namespace SimpleStateMachine.StructuralSearch.Helper;
5+
6+
public static class StringHelper
7+
{
8+
public static string FormatPrivateVar(this string str)
9+
{
10+
var stringBuilder = new StringBuilder(str.Length - 1);
11+
stringBuilder.Append(char.ToUpper(str[1]));
12+
stringBuilder.Append(str[2..]);
13+
return stringBuilder.ToString();
14+
}
15+
}

src/SimpleStateMachine.StructuralSearch/ParsingContext.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@ namespace SimpleStateMachine.StructuralSearch
66
public class ParsingContext : IParsingContext
77
{
88
public static readonly EmptyParsingContext Empty = new (SimpleStateMachine.StructuralSearch.Input.Empty);
9-
9+
private readonly Dictionary<string, IPlaceholder> _placeholders = new();
10+
public IInput Input { get; }
11+
1012
public ParsingContext(IInput input)
1113
{
1214
Input = input;
1315
}
14-
public readonly Dictionary<string, IPlaceholder> Placeholders = new();
15-
16-
public IInput Input { get; }
1716

1817
public bool TryGetPlaceholder(string name, out IPlaceholder value)
1918
{
20-
return Placeholders.TryGetValue(name, out value);
19+
return _placeholders.TryGetValue(name, out value);
2120
}
2221

2322
public void AddPlaceholder(IPlaceholder placeholder)
2423
{
25-
Placeholders[placeholder.Name] = placeholder;
24+
_placeholders[placeholder.Name] = placeholder;
2625
}
2726

2827
public IPlaceholder GetPlaceholder(string name)
2928
{
30-
return Placeholders[name];
29+
return _placeholders[name];
3130
}
3231

3332
public void Fill(IReadOnlyDictionary<string, IPlaceholder> placeholders)
@@ -36,13 +35,13 @@ public void Fill(IReadOnlyDictionary<string, IPlaceholder> placeholders)
3635

3736
foreach (var placeholder in placeholders)
3837
{
39-
Placeholders.Add(placeholder.Key, placeholder.Value);
38+
_placeholders.Add(placeholder.Key, placeholder.Value);
4039
}
4140
}
4241

4342
public IReadOnlyDictionary<string, IPlaceholder> Clear()
4443
{
45-
var placeholders = Placeholders
44+
var placeholders = _placeholders
4645
.OrderBy(x=> x.Value.Offset.Start)
4746
.ToDictionary(x=> x.Key, x=> x.Value);
4847

@@ -53,7 +52,7 @@ public IReadOnlyDictionary<string, IPlaceholder> Clear()
5352

5453
private void ClearInternal()
5554
{
56-
Placeholders.Clear();;
55+
_placeholders.Clear();;
5756
}
5857
}
5958
}

src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinarySubRule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Text.RegularExpressions;
3+
using SimpleStateMachine.StructuralSearch.Helper;
34

45
namespace SimpleStateMachine.StructuralSearch.Rules
56
{
@@ -28,7 +29,7 @@ public bool Execute(ref IParsingContext context)
2829
SubRuleType.StartsWith => left.StartsWith(right),
2930
SubRuleType.EndsWith => left.EndsWith(right),
3031
SubRuleType.Match => Regex.IsMatch(left, right),
31-
_ => throw new ArgumentOutOfRangeException()
32+
_ => throw new ArgumentOutOfRangeException(nameof(_type).FormatPrivateVar(), _type, null)
3233
};
3334
}
3435

src/SimpleStateMachine.StructuralSearch/Rules/FindRule/IsSubRule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using SimpleStateMachine.StructuralSearch.Extensions;
3+
using SimpleStateMachine.StructuralSearch.Helper;
34

45
namespace SimpleStateMachine.StructuralSearch.Rules
56
{
@@ -25,7 +26,7 @@ public bool Execute(ref IParsingContext context)
2526
PlaceholderType.Double => double.TryParse(value, out _),
2627
PlaceholderType.DateTime => DateTime.TryParse(value, out _),
2728
PlaceholderType.Guid => Guid.TryParse(value, out _),
28-
_ => throw new ArgumentOutOfRangeException()
29+
_ => throw new ArgumentOutOfRangeException(nameof(_argument).FormatPrivateVar(), _argument, null)
2930
};
3031
}
3132

src/SimpleStateMachine.StructuralSearch/Rules/FindRule/UnaryRule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using SimpleStateMachine.StructuralSearch.Helper;
23

34
namespace SimpleStateMachine.StructuralSearch.Rules
45
{
@@ -20,7 +21,7 @@ public bool Execute(ref IParsingContext context)
2021
return _type switch
2122
{
2223
UnaryRuleType.Not => !result,
23-
_ => throw new ArgumentOutOfRangeException()
24+
_ => throw new ArgumentOutOfRangeException(nameof(_type).FormatPrivateVar(), _type, null)
2425
};
2526
}
2627

src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderColumnParameter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using SimpleStateMachine.StructuralSearch.Helper;
23

34
namespace SimpleStateMachine.StructuralSearch.Rules
45
{
@@ -22,7 +23,7 @@ public string GetValue(ref IParsingContext context)
2223
{
2324
ColumnProperty.Start => column.Start,
2425
ColumnProperty.End => column.End,
25-
_ => throw new ArgumentOutOfRangeException()
26+
_ => throw new ArgumentOutOfRangeException(nameof(_property).FormatPrivateVar(), _property, null)
2627
};
2728

2829
return value.ToString();

src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderFileParameter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using SimpleStateMachine.StructuralSearch.Helper;
23

34
namespace SimpleStateMachine.StructuralSearch.Rules
45
{
@@ -25,7 +26,7 @@ public string GetValue(ref IParsingContext context)
2526
FileProperty.Extension => input.Extension,
2627
FileProperty.Name => input.Name,
2728
FileProperty.Lenght => input.Lenght.ToString(),
28-
_ => throw new ArgumentOutOfRangeException()
29+
_ => throw new ArgumentOutOfRangeException(nameof(_property).FormatPrivateVar(), _property, null)
2930
};
3031
}
3132

0 commit comments

Comments
 (0)