Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/UiPath.Workflow.Runtime/ActivityUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace System.Activities;
using Expressions;
using Internals;
using Runtime;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using Validation;

internal static class ActivityUtilities
Expand Down Expand Up @@ -47,6 +49,8 @@ internal static class ActivityUtilities
private static readonly Type outArgumentOfObjectType = typeof(OutArgument<object>);
private static readonly Type inOutArgumentOfObjectType = typeof(InOutArgument<object>);
private static PropertyChangedEventArgs propertyChangedEventArgs;

private static readonly ConcurrentDictionary<Type, ArgumentTypeInfo> argumentTypeCache = new();

// Can't delay create this one because we use object.ReferenceEquals on it in WorkflowInstance
private static readonly ReadOnlyDictionary<string, object> emptyParameters = new(new Dictionary<string, object>(0));
Expand Down Expand Up @@ -97,31 +101,54 @@ public static bool IsInScope(ActivityInstance potentialChild, ActivityInstance s

public static bool IsCompletedState(ActivityInstanceState state) => state != ActivityInstanceState.Executing;

private readonly struct ArgumentTypeInfo
{
public readonly ArgumentDirection Direction;
public readonly Type ArgumentType;

public ArgumentTypeInfo(ArgumentDirection direction, Type argumentType)
{
Direction = direction;
ArgumentType = argumentType;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryGetArgumentDirectionAndType(Type propertyType, out ArgumentDirection direction, out Type argumentType)
{
direction = ArgumentDirection.In; // default to In
argumentType = TypeHelper.ObjectType; // default to object

if (propertyType.IsGenericType)
{
if (argumentTypeCache.TryGetValue(propertyType, out ArgumentTypeInfo info))
{
direction = info.Direction;
argumentType = info.ArgumentType;
return true;
}

argumentType = propertyType.GetGenericArguments()[0];

Type genericType = propertyType.GetGenericTypeDefinition();

if (genericType == inArgumentGenericType)
{
argumentTypeCache.TryAdd(propertyType, new ArgumentTypeInfo(direction, argumentType));
return true;
}

if (genericType == outArgumentGenericType)
{
direction = ArgumentDirection.Out;
argumentTypeCache.TryAdd(propertyType, new ArgumentTypeInfo(direction, argumentType));
return true;
}

if (genericType == inOutArgumentGenericType)
{
direction = ArgumentDirection.InOut;
argumentTypeCache.TryAdd(propertyType, new ArgumentTypeInfo(direction, argumentType));
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/UiPath.Workflow.Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
[assembly: InternalsVisibleTo("UiPath.Workflow")]
[assembly: InternalsVisibleTo("TestCases.Workflows")]
[assembly: InternalsVisibleTo("TestCases.Runtime")]
[assembly: InternalsVisibleTo("CoreWf.Benchmarks")]
[assembly: InternalsVisibleTo("Perf.AssemblyReference.Benchmarks")]
Loading