Skip to content

Commit

Permalink
Revert "Merge pull request #282 from UiPath/fix/compat"
Browse files Browse the repository at this point in the history
This reverts commit b194d9d, reversing
changes made to bd19569.
  • Loading branch information
aoltean16 committed Nov 6, 2023
1 parent b194d9d commit 8b6ad1d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,25 +15,25 @@ namespace Microsoft.CSharp.Activities;

[DebuggerStepThrough]
[ContentProperty("ExpressionText")]
public class CSharpReference<TResult> : CodeActivity<Location<TResult>>, ITextExpression
public class CSharpReference<TResult> : TextExpressionBase<Location<TResult>>, ITextExpression
{
private CompiledExpressionInvoker _invoker;

public CSharpReference() => UseOldFastPath = true;

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<TResult>(this, metadata, ExpressionText, Language, true);
QueueForValidation<TResult>(metadata, true);
}

protected override Location<TResult> Execute(CodeActivityContext context) => (Location<TResult>)_invoker.InvokeExpression(context);
Expand Down
13 changes: 7 additions & 6 deletions src/UiPath.Workflow/Microsoft/CSharp/Activities/CSharpValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,26 +15,26 @@ namespace Microsoft.CSharp.Activities;

[DebuggerStepThrough]
[ContentProperty("ExpressionText")]
public class CSharpValue<TResult> : CodeActivity<TResult>, ITextExpression
public class CSharpValue<TResult> : TextExpressionBase<TResult>
{
private CompiledExpressionInvoker _invoker;

public CSharpValue() => UseOldFastPath = true;

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<TResult>(this, metadata, ExpressionText, Language, false);
QueueForValidation<TResult>(metadata, false);
}

protected override TResult Execute(CodeActivityContext context) => (TResult)_invoker.InvokeExpression(context);
protected override TResult Execute(CodeActivityContext context) => (TResult) _invoker.InvokeExpression(context);
}
Original file line number Diff line number Diff line change
@@ -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<TResult> : CodeActivity<TResult>, ITextExpression
{
private static readonly Func<ValidationExtension> _validationFunc = () => new();

public static bool QueueForValidation<T>(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<T>(CodeActivityMetadata metadata, bool isLocation)
{
if (metadata.Environment.CompileExpressions)
{
Expand All @@ -18,12 +26,12 @@ public static bool QueueForValidation<T>(Activity activity, CodeActivityMetadata
var extension = metadata.Environment.Extensions.GetOrAdd(_validationFunc);
extension.QueueExpressionForValidation<T>(new()
{
Activity = activity,
ExpressionText = expressionText,
Activity = this,
ExpressionText = ExpressionText,
IsLocation = isLocation,
ResultType = typeof(T),
Environment = metadata.Environment
}, language);
}, Language);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,8 +18,8 @@
namespace Microsoft.VisualBasic.Activities;

[DebuggerStepThrough]
public sealed class VisualBasicReference<TResult> : CodeActivity<Location<TResult>>, IValueSerializableExpression,
IExpressionContainer, ITextExpression
public sealed class VisualBasicReference<TResult> : TextExpressionBase<Location<TResult>>, IValueSerializableExpression,
IExpressionContainer
{
private Expression<Func<ActivityContext, TResult>> _expressionTree;
private CompiledExpressionInvoker _invoker;
Expand All @@ -28,12 +29,12 @@ public sealed class VisualBasicReference<TResult> : CodeActivity<Location<TResul

public VisualBasicReference(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)
{
Expand Down Expand Up @@ -85,7 +86,7 @@ protected override void CacheMetadata(CodeActivityMetadata metadata)
_expressionTree = null;
_invoker = new CompiledExpressionInvoker(this, true, metadata);

if (TextExpressionHelper.QueueForValidation<TResult>(this, metadata, ExpressionText, Language, true))
if (QueueForValidation<TResult>(metadata, true))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,8 +18,8 @@
namespace Microsoft.VisualBasic.Activities;

[DebuggerStepThrough]
public sealed class VisualBasicValue<TResult> : CodeActivity<TResult>, IValueSerializableExpression,
IExpressionContainer, ITextExpression
public sealed class VisualBasicValue<TResult> : TextExpressionBase<TResult>, IValueSerializableExpression,
IExpressionContainer
{
private Func<ActivityContext, TResult> _compiledExpression;
private Expression<Func<ActivityContext, TResult>> _expressionTree;
Expand All @@ -28,12 +29,12 @@ public sealed class VisualBasicValue<TResult> : CodeActivity<TResult>, 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)
{
Expand Down Expand Up @@ -86,7 +87,7 @@ protected override void CacheMetadata(CodeActivityMetadata metadata)
_expressionTree = null;
_invoker = new CompiledExpressionInvoker(this, false, metadata);

if (TextExpressionHelper.QueueForValidation<TResult>(this, metadata, ExpressionText, Language, false))
if (QueueForValidation<TResult>(metadata, false))
{
return;
}
Expand Down

0 comments on commit 8b6ad1d

Please sign in to comment.