Skip to content

Commit 19c16a3

Browse files
committed
ExpressionCompiler: Location compatible expressions should use only implicit cast, to cover implicit cast operators (STUD-78703)
1 parent 8681341 commit 19c16a3

File tree

1 file changed

+2
-31
lines changed

1 file changed

+2
-31
lines changed

src/UiPath.Workflow/XamlIntegration/TextExpressionCompiler.cs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file is part of Core WF which is licensed under the MIT license.
22
// See LICENSE file in the project root for full license information.
33

4+
using Microsoft.VisualBasic.Activities;
45
using System.Activities.Expressions;
56
using System.Activities.Internals;
67
using System.Activities.Runtime;
@@ -15,7 +16,6 @@
1516
using System.Linq;
1617
using System.Linq.Expressions;
1718
using System.Reflection;
18-
using Microsoft.VisualBasic.Activities;
1919

2020
namespace System.Activities.XamlIntegration;
2121

@@ -2530,34 +2530,13 @@ private string GetActivityFullName(TextExpressionCompilerSettings settings)
25302530

25312531
private string FormatWithTypeCast(string coreExpressionText, Type resultType)
25322532
{
2533-
if (resultType == null)
2533+
if (resultType == null || string.IsNullOrEmpty(coreExpressionText))
25342534
{
25352535
return coreExpressionText;
25362536
}
2537-
2538-
if (CanUseSafeCastOperator(resultType))
2539-
{
2540-
return SafeCastText(coreExpressionText, resultType);
2541-
}
2542-
25432537
return ExplicitCastText(coreExpressionText, resultType);
25442538
}
25452539

2546-
private static bool CanUseSafeCastOperator(Type targetType)
2547-
=> !targetType.IsValueType || IsNullableValueType(targetType);
2548-
2549-
private string SafeCastText(string expressionText, Type targetType)
2550-
{
2551-
string typeName = GetFriendlyTypeName(targetType);
2552-
if (typeName == null)
2553-
{
2554-
return expressionText;
2555-
}
2556-
2557-
// Use 'as' operator for reference types and nullable value types
2558-
return $"{expressionText} as {typeName}";
2559-
}
2560-
25612540
private string ExplicitCastText(string expressionText, Type targetType)
25622541
{
25632542
string typeName = GetFriendlyTypeName(targetType);
@@ -2569,14 +2548,6 @@ private string ExplicitCastText(string expressionText, Type targetType)
25692548
return $"(({typeName}){expressionText})";
25702549
}
25712550

2572-
/// <summary>
2573-
/// Helper method to check if a type is a nullable value type (e.g., int?, DateTime?)
2574-
/// </summary>
2575-
private static bool IsNullableValueType(Type type)
2576-
{
2577-
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
2578-
}
2579-
25802551
private string GetFriendlyTypeName(Type type)
25812552
{
25822553
return type is null ? null : _lazyProvider.Value.GetTypeOutput(new CodeTypeReference(type));

0 commit comments

Comments
 (0)