Skip to content

Commit b7fbdfe

Browse files
committed
проверка типов при установке свойств-перечислений
1 parent 80959b8 commit b7fbdfe

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/OneScript.Core/Exceptions/TypeConversionException.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ public class TypeConversionException : RuntimeException
1414
public TypeConversionException(BilingualString message) : base(message)
1515
{
1616
}
17+
18+
public TypeConversionException()
19+
: base(new BilingualString(
20+
"Íåñîîòâåòñòâèå òèïîâ",
21+
"Type mismatch"))
22+
{
23+
}
1724
}
1825
}

src/OneScript.StandardLibrary/Text/ConsoleContext.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public int XPos
4040
}
4141
set
4242
{
43-
Console.CursorLeft = Math.Min(value, Console.WindowWidth-1);
43+
Console.CursorLeft = Math.Min(value, Console.WindowWidth-1);
4444
}
4545
}
4646

@@ -54,8 +54,8 @@ public int YPos
5454
set
5555
{
5656
Console.CursorTop = Math.Min(value, Console.WindowHeight-1);
57+
}
5758
}
58-
}
5959

6060
[ContextMethod("ПрочитатьСтроку", "ReadLine")]
6161
public string ReadLine()
@@ -134,6 +134,8 @@ public IValue TextColor
134134
{
135135
Console.ForegroundColor = typed.UnderlyingValue;
136136
}
137+
else
138+
throw new TypeConversionException();
137139
}
138140
}
139141

@@ -144,7 +146,7 @@ public IValue BackgroundColor
144146
{
145147
try
146148
{
147-
return (ClrEnumValueWrapper<ConsoleColor>)GlobalsHelper.GetEnum<ConsoleColorEnum>().FromNativeValue(Console.BackgroundColor);
149+
return GlobalsHelper.GetEnum<ConsoleColorEnum>().FromNativeValue(Console.BackgroundColor);
148150
}
149151
catch (InvalidOperationException)
150152
{
@@ -157,6 +159,8 @@ public IValue BackgroundColor
157159
{
158160
Console.BackgroundColor = typed.UnderlyingValue;
159161
}
162+
else
163+
throw new TypeConversionException();
160164
}
161165
}
162166

0 commit comments

Comments
 (0)