@@ -8,6 +8,7 @@ This Source Code Form is subject to the terms of the
88using System ;
99using System . IO ;
1010using OneScript . Contexts ;
11+ using OneScript . Exceptions ;
1112using OneScript . Types ;
1213using ScriptEngine . Machine ;
1314using ScriptEngine . Machine . Contexts ;
@@ -301,30 +302,34 @@ public Stream GetUnderlyingStream()
301302 }
302303
303304 [ ScriptConstructor ( Name = "С указанием режима открытия" ) ]
304- public static FileStreamContext Constructor ( IValue filename , IValue openMode , IValue bufferSize = null )
305+ public static FileStreamContext Constructor ( IValue filename , IValue openMode , IValue param3 = null )
305306 {
306- if ( bufferSize == null || bufferSize . SystemType == BasicTypes . Number )
307+ if ( param3 == null || param3 . SystemType == BasicTypes . Number )
307308 {
308309 return new FileStreamContext (
309310 filename . AsString ( ) ,
310311 ContextValuesMarshaller . ConvertParam < FileOpenModeEnum > ( openMode ) ,
311312 FileAccessEnum . ReadAndWrite ,
312- ContextValuesMarshaller . ConvertParam < int > ( bufferSize ) ) ;
313+ ContextValuesMarshaller . ConvertParam < int > ( param3 ) ) ;
313314 }
314315 else
315316 {
316- // перегрузка методов не позволяет вызвать второй конструктор без доуточнения реальных типов
317- return Constructor (
318- filename ,
319- openMode ,
320- new ClrEnumValueWrapper < FileAccessEnum > ( null , FileAccessEnum . ReadAndWrite ) ,
321- bufferSize ) ;
317+ if ( param3 is ClrEnumValueWrapper < FileAccessEnum > access )
318+ return new FileStreamContext (
319+ filename . AsString ( ) ,
320+ ContextValuesMarshaller . ConvertParam < FileOpenModeEnum > ( openMode ) ,
321+ ContextValuesMarshaller . ConvertParam < FileAccessEnum > ( access ) ) ;
322+ else
323+ throw RuntimeException . InvalidNthArgumentType ( 3 ) ;
322324 }
323325 }
324326
325327 [ ScriptConstructor ( Name = "С указанием режима открытия и уровня доступа" ) ]
326328 public static FileStreamContext Constructor ( IValue filename , IValue openMode , IValue access , IValue bufferSize = null )
327329 {
330+ if ( bufferSize != null && bufferSize . SystemType != BasicTypes . Number )
331+ throw RuntimeException . InvalidNthArgumentType ( 4 ) ;
332+
328333 return new FileStreamContext (
329334 filename . AsString ( ) ,
330335 ContextValuesMarshaller . ConvertParam < FileOpenModeEnum > ( openMode ) ,
0 commit comments