@@ -52,27 +52,15 @@ public static BslValue Subtract(BslValue left, BslValue right)
5252 var dLeft = ( decimal ) left ;
5353 var dRight = ( decimal ) right ;
5454 return BslNumericValue . Create ( dLeft - dRight ) ; // or throw ConvertToNumberException();
55- }
56-
57- public static bool ToBoolean ( BslValue value )
58- {
59- return ( bool ) value ;
60- }
61-
62- public static decimal ToNumber ( BslValue value )
63- {
64- return ( decimal ) value ;
65- }
66-
67- public static DateTime ToDate ( BslValue value )
68- {
69- return ( DateTime ) value ;
70- }
71-
72- public static string ToString ( BslValue value )
73- {
74- return value . ToString ( ) ;
75- }
55+ }
56+
57+ public static bool ToBoolean ( BslValue value ) => ( bool ) value ;
58+
59+ public static decimal ToNumber ( BslValue value ) => ( decimal ) value ;
60+
61+ public static DateTime ToDate ( BslValue value ) => ( DateTime ) value ;
62+
63+ public static string ToString ( BslValue value ) => value . ToString ( ) ;
7664
7765 // FIXME: тут не должно быть Null, но из-за несовершенства мира они тут бывают. Когда задолбает - надо починить и убрать отсюда проверки на null
7866 public static bool Equality ( BslValue left , BslValue right )
@@ -99,32 +87,32 @@ public static int Comparison(BslValue left, BslValue right)
9987 }
10088
10189 public static BslValue WrapClrObjectToValue ( object value )
102- {
90+ {
10391 return value switch
10492 {
105- null => BslUndefinedValue . Instance ,
106- string s => BslStringValue . Create ( s ) ,
107- decimal d => BslNumericValue . Create ( d ) ,
108-
109- int n => BslNumericValue . Create ( n ) ,
110- uint n => BslNumericValue . Create ( n ) ,
111- short n => BslNumericValue . Create ( n ) ,
112- ushort n => BslNumericValue . Create ( n ) ,
113- byte n => BslNumericValue . Create ( n ) ,
114- sbyte n => BslNumericValue . Create ( n ) ,
115- long l => BslNumericValue . Create ( l ) ,
116- ulong l => BslNumericValue . Create ( l ) ,
117-
118- double dbl => BslNumericValue . Create ( ( decimal ) dbl ) ,
119- bool boolean => BslBooleanValue . Create ( boolean ) ,
120- DateTime date => BslDateValue . Create ( date ) ,
121- BslValue bslValue => bslValue ,
122- _ => throw new TypeConversionException ( new BilingualString (
123- $ "Невозможно преобразовать { value . GetType ( ) } в тип { nameof ( BslValue ) } ",
124- $ "Can't Convert { value . GetType ( ) } to { nameof ( BslValue ) } ") )
125- } ;
126- }
127-
93+ null => BslUndefinedValue . Instance ,
94+ string s => BslStringValue . Create ( s ) ,
95+ decimal d => BslNumericValue . Create ( d ) ,
96+
97+ int n => BslNumericValue . Create ( n ) ,
98+ uint n => BslNumericValue . Create ( n ) ,
99+ short n => BslNumericValue . Create ( n ) ,
100+ ushort n => BslNumericValue . Create ( n ) ,
101+ byte n => BslNumericValue . Create ( n ) ,
102+ sbyte n => BslNumericValue . Create ( n ) ,
103+ long l => BslNumericValue . Create ( l ) ,
104+ ulong l => BslNumericValue . Create ( l ) ,
105+
106+ double dbl => BslNumericValue . Create ( ( decimal ) dbl ) ,
107+ bool boolean => BslBooleanValue . Create ( boolean ) ,
108+ DateTime date => BslDateValue . Create ( date ) ,
109+ BslValue bslValue => bslValue ,
110+ _ => throw new TypeConversionException ( new BilingualString (
111+ $ "Невозможно преобразовать { value . GetType ( ) } в тип { nameof ( BslValue ) } ",
112+ $ "Can't Convert { value . GetType ( ) } to { nameof ( BslValue ) } ") )
113+ } ;
114+ }
115+
128116 public static BslValue ConstructorCall ( ITypeManager typeManager , IServiceContainer services , string typeName , IBslProcess process , BslValue [ ] args )
129117 {
130118 var type = typeManager . GetTypeByName ( typeName ) ;
@@ -138,39 +126,33 @@ public static BslValue ConstructorCall(ITypeManager typeManager, IServiceContain
138126 } ;
139127
140128 return ( BslValue ) factory . Activate ( context , args . Cast < IValue > ( ) . ToArray ( ) ) ;
141- }
142-
143- // TODO: Сделать прямой маппинг на статические фабрики-методы, а не через Factory.Activate
144- public static T StrictConstructorCall < T > ( ITypeManager typeManager , IServiceContainer services , string typeName , IBslProcess process , BslValue [ ] args )
129+ }
130+
131+ // TODO: Сделать прямой маппинг на статические фабрики-методы, а не через Factory.Activate
132+ public static T StrictConstructorCall < T > ( ITypeManager typeManager , IServiceContainer services ,
133+ string typeName , IBslProcess process , BslValue [ ] args )
145134 where T : BslValue
146- {
147- return ( T ) ConstructorCall ( typeManager , services , typeName , process , args ) ;
148- }
135+ => ( T ) ConstructorCall ( typeManager , services , typeName , process , args ) ;
149136
150137 public static BslObjectValue GetExceptionInfo ( IExceptionInfoFactory factory , Exception e )
151- {
152- return factory . GetExceptionInfo ( e ) ;
153- }
138+ => factory . GetExceptionInfo ( e ) ;
154139
155140 public static BslTypeValue GetTypeByName ( ITypeManager manager , string name )
156- {
157- var foundType = manager . GetTypeByName ( name ) ;
158- return new BslTypeValue ( foundType ) ;
159- }
141+ => new ( manager . GetTypeByName ( name ) ) ;
160142
161143 public static BslValue GetIndexedValue ( object target , BslValue index )
162144 {
163- if ( ! ( target is IRuntimeContextInstance context ) || ! context . IsIndexed )
145+ if ( target is not IRuntimeContextInstance context || ! context . IsIndexed )
164146 {
165147 throw RuntimeException . IndexedAccessIsNotSupportedException ( ) ;
166148 }
167149
168- return ( BslValue ) context . GetIndexedValue ( ( IValue ) index ) ;
150+ return ( BslValue ) context . GetIndexedValue ( index ) ;
169151 }
170152
171153 public static void SetIndexedValue ( object target , BslValue index , BslValue value )
172154 {
173- if ( ! ( target is IRuntimeContextInstance context ) || ! context . IsIndexed )
155+ if ( target is not IRuntimeContextInstance context || ! context . IsIndexed )
174156 {
175157 throw RuntimeException . IndexedAccessIsNotSupportedException ( ) ;
176158 }
@@ -180,7 +162,7 @@ public static void SetIndexedValue(object target, BslValue index, BslValue value
180162
181163 public static BslValue GetPropertyValue ( object target , string propertyName )
182164 {
183- if ( ! ( target is IRuntimeContextInstance context ) )
165+ if ( target is not IRuntimeContextInstance context )
184166 throw BslExceptions . ValueIsNotObjectException ( ) ;
185167
186168 var propIndex = context . GetPropertyNumber ( propertyName ) ;
@@ -189,7 +171,7 @@ public static BslValue GetPropertyValue(object target, string propertyName)
189171
190172 public static BslValue TryCallContextMethod ( BslValue instance , string methodName , IBslProcess process , BslValue [ ] arguments )
191173 {
192- if ( ! ( instance is IRuntimeContextInstance context ) )
174+ if ( instance is not IRuntimeContextInstance context )
193175 throw BslExceptions . ValueIsNotObjectException ( ) ;
194176
195177 return CallContextMethod ( context , methodName , process , arguments ) ;
0 commit comments