diff --git a/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpReference.cs b/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpReference.cs index 0d3dbaf3..121afdad 100644 --- a/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpReference.cs +++ b/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpReference.cs @@ -5,6 +5,7 @@ using System.Activities; using System.Activities.Expressions; using System.Activities.Internals; +using System.Activities.Validation; using System.ComponentModel; using System.Diagnostics; using System.Linq.Expressions; @@ -14,7 +15,7 @@ namespace Microsoft.CSharp.Activities; [DebuggerStepThrough] [ContentProperty("ExpressionText")] -public class CSharpReference : CodeActivity>, ITextExpression +public class CSharpReference : TextExpressionBase>, ITextExpression { private CompiledExpressionInvoker _invoker; @@ -22,17 +23,17 @@ public class CSharpReference : CodeActivity>, ITextEx public CSharpReference(string expressionText) : this() => ExpressionText = expressionText; - public string ExpressionText { get; set; } + public override string ExpressionText { get; set; } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Language => CSharpHelper.Language; + public override string Language => CSharpHelper.Language; - public Expression GetExpressionTree() => IsMetadataCached ? _invoker.GetExpressionTree() : throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached)); + public override Expression GetExpressionTree() => IsMetadataCached ? _invoker.GetExpressionTree() : throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached)); protected override void CacheMetadata(CodeActivityMetadata metadata) { _invoker = new CompiledExpressionInvoker(this, true, metadata); - TextExpressionHelper.QueueForValidation(this, metadata, ExpressionText, Language, true); + QueueForValidation(metadata, true); } protected override Location Execute(CodeActivityContext context) => (Location)_invoker.InvokeExpression(context); diff --git a/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpValue.cs b/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpValue.cs index 1d65b1fb..044b4b6d 100644 --- a/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpValue.cs +++ b/src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpValue.cs @@ -5,6 +5,7 @@ using System.Activities; using System.Activities.Expressions; using System.Activities.Internals; +using System.Activities.Validation; using System.ComponentModel; using System.Diagnostics; using System.Linq.Expressions; @@ -14,7 +15,7 @@ namespace Microsoft.CSharp.Activities; [DebuggerStepThrough] [ContentProperty("ExpressionText")] -public class CSharpValue : CodeActivity, ITextExpression +public class CSharpValue : TextExpressionBase { private CompiledExpressionInvoker _invoker; @@ -22,18 +23,18 @@ public class CSharpValue : CodeActivity, ITextExpression public CSharpValue(string expressionText) : this() => ExpressionText = expressionText; - public string ExpressionText { get; set; } + public override string ExpressionText { get; set; } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Language => CSharpHelper.Language; + public override string Language => CSharpHelper.Language; - public Expression GetExpressionTree() => IsMetadataCached ? _invoker.GetExpressionTree() : throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached)); + public override Expression GetExpressionTree() => IsMetadataCached ? _invoker.GetExpressionTree() : throw FxTrace.Exception.AsError(new InvalidOperationException(SR.ActivityIsUncached)); protected override void CacheMetadata(CodeActivityMetadata metadata) { _invoker = new CompiledExpressionInvoker(this, false, metadata); - TextExpressionHelper.QueueForValidation(this, metadata, ExpressionText, Language, false); + QueueForValidation(metadata, false); } - protected override TResult Execute(CodeActivityContext context) => (TResult)_invoker.InvokeExpression(context); + protected override TResult Execute(CodeActivityContext context) => (TResult) _invoker.InvokeExpression(context); } \ No newline at end of file diff --git a/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/TextExpressionHelper.cs b/src/UiPath.Workflow/Microsoft/TextExpressionBase.cs similarity index 55% rename from src/UiPath.Workflow/Microsoft/VisualBasic/Activities/TextExpressionHelper.cs rename to src/UiPath.Workflow/Microsoft/TextExpressionBase.cs index a1f92d15..6014018e 100644 --- a/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/TextExpressionHelper.cs +++ b/src/UiPath.Workflow/Microsoft/TextExpressionBase.cs @@ -1,12 +1,20 @@ -using System.Activities.Validation; +using System.Activities.Expressions; +using System.Activities.Validation; +using System.Linq.Expressions; namespace System.Activities { - internal static class TextExpressionHelper + public abstract class TextExpressionBase : CodeActivity, ITextExpression { private static readonly Func _validationFunc = () => new(); - public static bool QueueForValidation(Activity activity, CodeActivityMetadata metadata, string expressionText, string language, bool isLocation) + public abstract string ExpressionText { get; set; } + + public abstract string Language { get; } + + public abstract Expression GetExpressionTree(); + + protected bool QueueForValidation(CodeActivityMetadata metadata, bool isLocation) { if (metadata.Environment.CompileExpressions) { @@ -18,12 +26,12 @@ public static bool QueueForValidation(Activity activity, CodeActivityMetadata var extension = metadata.Environment.Extensions.GetOrAdd(_validationFunc); extension.QueueExpressionForValidation(new() { - Activity = activity, - ExpressionText = expressionText, + Activity = this, + ExpressionText = ExpressionText, IsLocation = isLocation, ResultType = typeof(T), Environment = metadata.Environment - }, language); + }, Language); return true; } diff --git a/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicReference.cs b/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicReference.cs index 5010b60f..099fde48 100644 --- a/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicReference.cs +++ b/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicReference.cs @@ -7,6 +7,7 @@ using System.Activities.Expressions; using System.Activities.Internals; using System.Activities.Runtime; +using System.Activities.Validation; using System.Activities.XamlIntegration; using System.ComponentModel; using System.Diagnostics; @@ -17,8 +18,8 @@ namespace Microsoft.VisualBasic.Activities; [DebuggerStepThrough] -public sealed class VisualBasicReference : CodeActivity>, IValueSerializableExpression, - IExpressionContainer, ITextExpression +public sealed class VisualBasicReference : TextExpressionBase>, IValueSerializableExpression, + IExpressionContainer { private Expression> _expressionTree; private CompiledExpressionInvoker _invoker; @@ -28,12 +29,12 @@ public sealed class VisualBasicReference : CodeActivity ExpressionText = expressionText; - public string ExpressionText { get; set; } + public override string ExpressionText { get; set; } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Language => VisualBasicHelper.Language; + public override string Language => VisualBasicHelper.Language; - public Expression GetExpressionTree() + public override Expression GetExpressionTree() { if (IsMetadataCached) { @@ -85,7 +86,7 @@ protected override void CacheMetadata(CodeActivityMetadata metadata) _expressionTree = null; _invoker = new CompiledExpressionInvoker(this, true, metadata); - if (TextExpressionHelper.QueueForValidation(this, metadata, ExpressionText, Language, true)) + if (QueueForValidation(metadata, true)) { return; } diff --git a/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicValue.cs b/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicValue.cs index 2fb8188e..05d9da5a 100644 --- a/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicValue.cs +++ b/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicValue.cs @@ -7,6 +7,7 @@ using System.Activities.Expressions; using System.Activities.Internals; using System.Activities.Runtime; +using System.Activities.Validation; using System.Activities.XamlIntegration; using System.ComponentModel; using System.Diagnostics; @@ -17,8 +18,8 @@ namespace Microsoft.VisualBasic.Activities; [DebuggerStepThrough] -public sealed class VisualBasicValue : CodeActivity, IValueSerializableExpression, - IExpressionContainer, ITextExpression +public sealed class VisualBasicValue : TextExpressionBase, IValueSerializableExpression, + IExpressionContainer { private Func _compiledExpression; private Expression> _expressionTree; @@ -28,12 +29,12 @@ public sealed class VisualBasicValue : CodeActivity, IValueSer public VisualBasicValue(string expressionText) : this() => ExpressionText = expressionText; - public string ExpressionText { get; set; } + public override string ExpressionText { get; set; } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Language => VisualBasicHelper.Language; + public override string Language => VisualBasicHelper.Language; - public Expression GetExpressionTree() + public override Expression GetExpressionTree() { if (!IsMetadataCached) { @@ -86,7 +87,7 @@ protected override void CacheMetadata(CodeActivityMetadata metadata) _expressionTree = null; _invoker = new CompiledExpressionInvoker(this, false, metadata); - if (TextExpressionHelper.QueueForValidation(this, metadata, ExpressionText, Language, false)) + if (QueueForValidation(metadata, false)) { return; }