@@ -101,11 +101,6 @@ public static LocalValue ConvertFrom(object? value)
101101 }
102102 }
103103
104- public static LocalValue ConvertFrom ( bool value )
105- {
106- return new BooleanLocalValue ( value ) ;
107- }
108-
109104 public static LocalValue ConvertFrom ( bool ? value )
110105 {
111106 if ( value is bool b )
@@ -116,11 +111,6 @@ public static LocalValue ConvertFrom(bool? value)
116111 return new NullLocalValue ( ) ;
117112 }
118113
119- public static LocalValue ConvertFrom ( int value )
120- {
121- return new NumberLocalValue ( value ) ;
122- }
123-
124114 public static LocalValue ConvertFrom ( int ? value )
125115 {
126116 if ( value is int b )
@@ -131,11 +121,6 @@ public static LocalValue ConvertFrom(int? value)
131121 return new NullLocalValue ( ) ;
132122 }
133123
134- public static LocalValue ConvertFrom ( double value )
135- {
136- return new NumberLocalValue ( value ) ;
137- }
138-
139124 public static LocalValue ConvertFrom ( double ? value )
140125 {
141126 if ( value is double b )
@@ -146,11 +131,6 @@ public static LocalValue ConvertFrom(double? value)
146131 return new NullLocalValue ( ) ;
147132 }
148133
149- public static LocalValue ConvertFrom ( long value )
150- {
151- return new NumberLocalValue ( value ) ;
152- }
153-
154134 public static LocalValue ConvertFrom ( long ? value )
155135 {
156136 if ( value is long b )
@@ -171,52 +151,63 @@ public static LocalValue ConvertFrom(string? value)
171151 return new NullLocalValue ( ) ;
172152 }
173153
174- public static LocalValue ConvertFrom ( DateTime dateTime )
154+ public static LocalValue ConvertFrom ( DateTime ? value )
175155 {
176- return new DateLocalValue ( dateTime . ToString ( "o" ) ) ;
156+ if ( value is null )
157+ {
158+ return new NullLocalValue ( ) ;
159+ }
160+
161+ return new DateLocalValue ( value . Value . ToString ( "o" ) ) ;
177162 }
178163
179- public static LocalValue ConvertFrom ( BigInteger bigInt )
164+ public static LocalValue ConvertFrom ( BigInteger ? value )
180165 {
181- return new BigIntLocalValue ( bigInt . ToString ( ) ) ;
166+ if ( value is not null )
167+ {
168+ return new BigIntLocalValue ( value . Value . ToString ( ) ) ;
169+ }
170+
171+ return new NullLocalValue ( ) ;
182172 }
183173
184- public static LocalValue ConvertFrom ( IEnumerable < object ? > ? values )
174+ public static LocalValue ConvertFrom ( IEnumerable < object ? > ? value )
185175 {
186- if ( values is null )
176+ if ( value is null )
187177 {
188178 return new NullLocalValue ( ) ;
189179 }
190180
191- LocalValue [ ] convertedList = values . Select ( ConvertFrom ) . ToArray ( ) ;
181+ LocalValue [ ] convertedList = [ .. value . Select ( ConvertFrom ) ] ;
192182 return new ArrayLocalValue ( convertedList ) ;
193183 }
194184
195- public static LocalValue ConvertFrom < T > ( IList < T ? > ? values )
185+ public static LocalValue ConvertFrom < T > ( IList < T ? > ? value )
196186 {
197- if ( values is null )
187+ if ( value is null )
198188 {
199189 return new NullLocalValue ( ) ;
200190 }
201191
202- List < LocalValue > convertedList = [ .. values . Select ( element => ConvertFrom ( element ) ) ] ;
192+ List < LocalValue > convertedList = [ .. value . Select ( element => ConvertFrom ( element ) ) ] ;
203193 return new ArrayLocalValue ( convertedList ) ;
204194 }
205195
206- public static LocalValue ConvertFrom < TValue > ( IDictionary < string , TValue ? > ? dictionary )
196+ public static LocalValue ConvertFrom < TValue > ( IDictionary < string , TValue ? > ? value )
207197 {
208- return ConvertFrom < string , TValue > ( dictionary ) ;
198+ return ConvertFrom < string , TValue > ( value ) ;
209199 }
210200
211- public static LocalValue ConvertFrom < TKey , TValue > ( IDictionary < TKey , TValue ? > ? dictionary )
201+ public static LocalValue ConvertFrom < TKey , TValue > ( IDictionary < TKey , TValue ? > ? value )
212202 {
213- if ( dictionary is null )
203+ if ( value is null )
214204 {
215205 return new NullLocalValue ( ) ;
216206 }
217207
218- var bidiObject = new List < List < LocalValue > > ( dictionary . Count ) ;
219- foreach ( KeyValuePair < TKey , TValue ? > item in dictionary )
208+ var bidiObject = new List < List < LocalValue > > ( value . Count ) ;
209+
210+ foreach ( KeyValuePair < TKey , TValue ? > item in value )
220211 {
221212 bidiObject . Add ( [ ConvertFrom ( item . Key ) , ConvertFrom ( item . Value ) ] ) ;
222213 }
@@ -229,14 +220,15 @@ public static LocalValue ConvertFrom<TKey, TValue>(IDictionary<TKey, TValue?>? d
229220 return new MapLocalValue ( bidiObject ) ;
230221 }
231222
232- public static LocalValue ConvertFrom < T > ( ISet < T ? > ? set )
223+ public static LocalValue ConvertFrom < T > ( ISet < T ? > ? value )
233224 {
234- if ( set is null )
225+ if ( value is null )
235226 {
236227 return new NullLocalValue ( ) ;
237228 }
238229
239- LocalValue [ ] convertedValues = [ .. set . Select ( x => ConvertFrom ( x ) ) ] ;
230+ LocalValue [ ] convertedValues = [ .. value . Select ( x => ConvertFrom ( x ) ) ] ;
231+
240232 return new SetLocalValue ( convertedValues ) ;
241233 }
242234
@@ -252,9 +244,11 @@ private static LocalValue ReflectionBasedConvertFrom(object? value)
252244 System . Reflection . PropertyInfo [ ] properties = value . GetType ( ) . GetProperties ( Flags ) ;
253245
254246 var values = new List < List < LocalValue > > ( properties . Length ) ;
247+
255248 foreach ( System . Reflection . PropertyInfo ? property in properties )
256249 {
257250 object ? propertyValue ;
251+
258252 try
259253 {
260254 propertyValue = property . GetValue ( value ) ;
@@ -263,6 +257,7 @@ private static LocalValue ReflectionBasedConvertFrom(object? value)
263257 {
264258 throw new BiDiException ( $ "Could not retrieve property { property . Name } from { property . DeclaringType } ", ex ) ;
265259 }
260+
266261 values . Add ( [ property. Name , ConvertFrom ( propertyValue ) ] ) ;
267262 }
268263
0 commit comments