Skip to content

Commit 44a55bd

Browse files
committed
выделено исключение сравнения
1 parent a857ede commit 44a55bd

File tree

7 files changed

+45
-22
lines changed

7 files changed

+45
-22
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*----------------------------------------------------------
2+
This Source Code Form is subject to the terms of the
3+
Mozilla Public License, v.2.0. If a copy of the MPL
4+
was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
----------------------------------------------------------*/
7+
8+
using System;
9+
using OneScript.Localization;
10+
11+
namespace OneScript.Exceptions
12+
{
13+
public class ComparisonException : RuntimeException
14+
{
15+
public ComparisonException(BilingualString message) : base(message)
16+
{
17+
}
18+
19+
public static ComparisonException NotSupported()
20+
{
21+
return new ComparisonException(new BilingualString(
22+
$"Сравнение на больше/меньше для типа не поддерживается",
23+
$"Greater-than/Less-than comparison operations are not supported"));
24+
}
25+
26+
public static ComparisonException NotSupported(string type)
27+
{
28+
return new ComparisonException(new BilingualString(
29+
$"Сравнение на больше/меньше для типа '{type}' не поддерживается",
30+
$"Greater-than/Less-than comparison operations are not supported for '{type}'"));
31+
}
32+
33+
public static ComparisonException NotSupported(string type1, string type2)
34+
{
35+
return new ComparisonException(new BilingualString(
36+
$"Сравнение на больше/меньше типов '{type1}' и '{type2}' не поддерживается ",
37+
$"Greater-than/Less-than comparison operations are not supported for '{type1}' and '{type2}'"));
38+
}
39+
}
40+
}

src/OneScript.Core/Exceptions/RuntimeException.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,6 @@ public static RuntimeException InvalidNthArgumentValue(int argNum)
118118
$"Invalid value for argument number {argNum}");
119119
}
120120

121-
public static RuntimeException ComparisonNotSupportedException()
122-
{
123-
return new RuntimeException(
124-
"Сравнение на больше/меньше для данного типа не поддерживается",
125-
"Greater-than/Less-than comparison operations are not supported");
126-
}
127-
128-
public static RuntimeException ComparisonNotSupportedException(string type1, string type2)
129-
{
130-
return new RuntimeException(
131-
$"Сравнение на больше/меньше для данного типа не поддерживается {type1} <-> {type2}",
132-
$"Greater-than/Less-than comparison operations are not supported for {type1} <-> {type2}");
133-
}
134-
135121
public static RuntimeException IndexedAccessIsNotSupportedException()
136122
{
137123
return new RuntimeException(

src/OneScript.Core/Values/BslObjectValue.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ public abstract class BslObjectValue : BslValue
1414
{
1515
public override int CompareTo(BslValue other)
1616
{
17-
var msg = new BilingualString("Сравнение на больше/меньше для данного типа не поддерживается",
18-
"Comparison for less/greater is not supported for this type");
19-
20-
throw new RuntimeException(msg);
17+
throw ComparisonException.NotSupported();
2118
}
2219

2320
public override bool Equals(BslValue other)

src/OneScript.Core/Values/BslPrimitiveValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override int CompareTo(BslValue other)
3131
typeOfOther ??= GetType().ToString();
3232
}
3333

34-
throw RuntimeException.ComparisonNotSupportedException(typeOfThis, typeOfOther);
34+
throw ComparisonException.NotSupported(typeOfThis, typeOfOther);
3535
}
3636

3737
public override bool Equals(BslValue other) => false;

src/OneScript.Core/Values/EnumerationValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override string ToString()
4848

4949
public override int CompareTo(BslValue other)
5050
{
51-
throw RuntimeException.ComparisonNotSupportedException();
51+
throw ComparisonException.NotSupported();
5252
}
5353

5454
public override bool Equals(BslValue other)

src/OneScript.StandardLibrary/GuidWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override int CompareTo(BslValue other)
6262
{
6363
GuidWrapper otherUuid = other.GetRawValue() as GuidWrapper;
6464
if (otherUuid == null)
65-
throw RuntimeException.ComparisonNotSupportedException();
65+
throw ComparisonException.NotSupported();
6666

6767
return _value.CompareTo(otherUuid._value);
6868
}

src/ScriptEngine/Machine/Contexts/ContextIValueImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override TypeDescriptor SystemType
6262

6363
public override int CompareTo(BslValue other)
6464
{
65-
throw RuntimeException.ComparisonNotSupportedException();
65+
throw ComparisonException.NotSupported();
6666
}
6767

6868
#endregion

0 commit comments

Comments
 (0)