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 ;
45using System . Activities . Expressions ;
56using System . Activities . Internals ;
67using System . Activities . Runtime ;
1516using System . Linq ;
1617using System . Linq . Expressions ;
1718using System . Reflection ;
18- using Microsoft . VisualBasic . Activities ;
1919
2020namespace 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