Skip to content

Commit

Permalink
проверка типов при установке свойств-перечислений
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Rm committed Jun 21, 2024
1 parent 80959b8 commit b7fbdfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/OneScript.Core/Exceptions/TypeConversionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ public class TypeConversionException : RuntimeException
public TypeConversionException(BilingualString message) : base(message)
{
}

public TypeConversionException()
: base(new BilingualString(
"Íåñîîòâåòñòâèå òèïîâ",
"Type mismatch"))
{
}
}
}
10 changes: 7 additions & 3 deletions src/OneScript.StandardLibrary/Text/ConsoleContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int XPos
}
set
{
Console.CursorLeft = Math.Min(value, Console.WindowWidth-1);
Console.CursorLeft = Math.Min(value, Console.WindowWidth-1);
}
}

Expand All @@ -54,8 +54,8 @@ public int YPos
set
{
Console.CursorTop = Math.Min(value, Console.WindowHeight-1);
}
}
}

[ContextMethod("ПрочитатьСтроку", "ReadLine")]
public string ReadLine()
Expand Down Expand Up @@ -134,6 +134,8 @@ public IValue TextColor
{
Console.ForegroundColor = typed.UnderlyingValue;
}
else
throw new TypeConversionException();
}
}

Expand All @@ -144,7 +146,7 @@ public IValue BackgroundColor
{
try
{
return (ClrEnumValueWrapper<ConsoleColor>)GlobalsHelper.GetEnum<ConsoleColorEnum>().FromNativeValue(Console.BackgroundColor);
return GlobalsHelper.GetEnum<ConsoleColorEnum>().FromNativeValue(Console.BackgroundColor);
}
catch (InvalidOperationException)
{
Expand All @@ -157,6 +159,8 @@ public IValue BackgroundColor
{
Console.BackgroundColor = typed.UnderlyingValue;
}
else
throw new TypeConversionException();
}
}

Expand Down

0 comments on commit b7fbdfe

Please sign in to comment.