@@ -59,7 +59,7 @@ public ValueContainer(string stringValue)
5959
6060 public ValueContainer ( float floatValue )
6161 {
62- _value = floatValue ;
62+ _value = Convert . ToDouble ( floatValue ) ;
6363 _type = ValueType . Float ;
6464 }
6565
@@ -250,9 +250,22 @@ private ValueContainer JsonToValueContainer(JToken json)
250250 case JValue jValue :
251251 if ( jValue . HasValues )
252252 {
253- throw new PowerAutomateMockUpException ( "When parsing JToken to ValueContainer, the JToken as JValue can only contain one value." ) ;
253+ throw new PowerAutomateMockUpException (
254+ "When parsing JToken to ValueContainer, the JToken as JValue can only contain one value." ) ;
254255 }
255- return jValue . Value == null ? new ValueContainer ( ) : new ValueContainer ( jValue . Value . ToString ( ) , true ) ;
256+
257+ return jValue . Type switch
258+ {
259+ JTokenType . Boolean => new ValueContainer ( jValue . Value < bool > ( ) ) ,
260+ JTokenType . Integer => new ValueContainer ( jValue . Value < int > ( ) ) ,
261+ JTokenType . Float => new ValueContainer ( jValue . Value < float > ( ) ) ,
262+ JTokenType . Null => new ValueContainer ( ) ,
263+ JTokenType . String => new ValueContainer ( jValue . Value < string > ( ) ) ,
264+ JTokenType . None => new ValueContainer ( ) ,
265+ JTokenType . Guid => new ValueContainer ( jValue . Value < Guid > ( ) . ToString ( ) ) ,
266+ _ => throw new PowerAutomateMockUpException (
267+ $ "{ jValue . Type } is not yet supported in ValueContainer conversion")
268+ } ;
256269 default :
257270 throw new PowerAutomateMockUpException ( "Could not parse JToken to ValueContainer." ) ;
258271 }
@@ -380,6 +393,19 @@ public bool Equals(ValueContainer other)
380393
381394 return thisDict . Count == otherDict . Count && ! thisDict . Except ( otherDict ) . Any ( ) ;
382395 }
396+ case ValueType . Integer when other . _type == ValueType . Float :
397+ var v = ( double ) _value ;
398+ return Math . Abs ( Math . Floor ( v ) - other . _value ) < double . Epsilon ;
399+ case ValueType . Float when other . _type == ValueType . Integer :
400+ {
401+ return Math . Abs ( Math . Floor ( _value ) - other . _value ) < double . Epsilon ;
402+ }
403+ case ValueType . Float :
404+ {
405+ // TODO: Figure out how to handle comparison and in general how to handle float/double..
406+ // assignee: thygesteffensen
407+ return Math . Abs ( _value - other . _value ) < 0.01 ;
408+ }
383409 default :
384410 return Equals ( _value , other . _value ) && _type == other . _type ;
385411 }
0 commit comments