Skip to content

Commit

Permalink
Added support for + operation on strings
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Jan 31, 2025
1 parent 913dd0b commit f7a9262
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Gum/Plugins/InternalPlugins/VariableGrid/EvaluatedSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,33 @@ private static void GetDynamicValues(object obj1, object obj2, out dynamic dynam
dynamicValue1 = null;
dynamicValue2 = null;

if(!TryGetNumericType(obj1, out Type type1) || !TryGetNumericType(obj2, out Type type2))
var isFirstNumeric = TryGetNumericType(obj1, out Type type1);
var isSecondNumeric = TryGetNumericType(obj2, out Type type2);

if(isFirstNumeric && isSecondNumeric)
{
return;
}

// Find the larger (wider) type to ensure proper addition
var targetType = GetWiderNumericType(type1, type2);

// Find the larger (wider) type to ensure proper addition
var targetType = GetWiderNumericType(type1, type2);
// Convert both numbers to the wider type
var value1 = Convert.ChangeType(obj1, targetType);
var value2 = Convert.ChangeType(obj2, targetType);

// Convert both numbers to the wider type
var value1 = Convert.ChangeType(obj1, targetType);
var value2 = Convert.ChangeType(obj2, targetType);
// Perform the addition
dynamicValue1 = value1;
dynamicValue2 = value2;
}
else
{
var isFirstNumericOrString = isFirstNumeric || obj1 is string;
var isSecondNumericOrString = isSecondNumeric || obj2 is string;

// Perform the addition
dynamicValue1 = value1;
dynamicValue2 = value2;
if(isFirstNumericOrString && isSecondNumericOrString)
{
dynamicValue1 = obj1;
dynamicValue2 = obj2;
}
}
}
private static EvaluatedSyntax FromSyntaxAndValue(SyntaxNode syntaxNode, object value)
{
Expand Down

0 comments on commit f7a9262

Please sign in to comment.