From 19c16a3fc6bc6c5bbae6af5f4cb44f79322012d5 Mon Sep 17 00:00:00 2001 From: gpanaitescu Date: Tue, 20 Jan 2026 15:18:56 +0200 Subject: [PATCH] ExpressionCompiler: Location compatible expressions should use only implicit cast, to cover implicit cast operators (STUD-78703) --- .../XamlIntegration/TextExpressionCompiler.cs | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/UiPath.Workflow/XamlIntegration/TextExpressionCompiler.cs b/src/UiPath.Workflow/XamlIntegration/TextExpressionCompiler.cs index 6d9ba307..95e0d600 100644 --- a/src/UiPath.Workflow/XamlIntegration/TextExpressionCompiler.cs +++ b/src/UiPath.Workflow/XamlIntegration/TextExpressionCompiler.cs @@ -1,6 +1,7 @@ // This file is part of Core WF which is licensed under the MIT license. // See LICENSE file in the project root for full license information. +using Microsoft.VisualBasic.Activities; using System.Activities.Expressions; using System.Activities.Internals; using System.Activities.Runtime; @@ -15,7 +16,6 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; -using Microsoft.VisualBasic.Activities; namespace System.Activities.XamlIntegration; @@ -2530,34 +2530,13 @@ private string GetActivityFullName(TextExpressionCompilerSettings settings) private string FormatWithTypeCast(string coreExpressionText, Type resultType) { - if (resultType == null) + if (resultType == null || string.IsNullOrEmpty(coreExpressionText)) { return coreExpressionText; } - - if (CanUseSafeCastOperator(resultType)) - { - return SafeCastText(coreExpressionText, resultType); - } - return ExplicitCastText(coreExpressionText, resultType); } - private static bool CanUseSafeCastOperator(Type targetType) - => !targetType.IsValueType || IsNullableValueType(targetType); - - private string SafeCastText(string expressionText, Type targetType) - { - string typeName = GetFriendlyTypeName(targetType); - if (typeName == null) - { - return expressionText; - } - - // Use 'as' operator for reference types and nullable value types - return $"{expressionText} as {typeName}"; - } - private string ExplicitCastText(string expressionText, Type targetType) { string typeName = GetFriendlyTypeName(targetType); @@ -2569,14 +2548,6 @@ private string ExplicitCastText(string expressionText, Type targetType) return $"(({typeName}){expressionText})"; } - /// - /// Helper method to check if a type is a nullable value type (e.g., int?, DateTime?) - /// - private static bool IsNullableValueType(Type type) - { - return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); - } - private string GetFriendlyTypeName(Type type) { return type is null ? null : _lazyProvider.Value.GetTypeOutput(new CodeTypeReference(type));