-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathDecrement.cs
More file actions
57 lines (51 loc) · 1.97 KB
/
Decrement.cs
File metadata and controls
57 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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 System.Activities.Validation;
using System.Linq.Expressions;
using System.Numerics;
namespace System.Activities.Expressions
{
/// <summary>
/// A code activity which decrements a numeral.
/// </summary>
/// <typeparam name="TNumeral">A numeric value, such as <see langword="int" /> or <see langword="long" />.</typeparam>
public sealed class Decrement<TNumeral> : CodeActivity<TNumeral>
#if NET7_0_OR_GREATER
where TNumeral : IIncrementOperators<TNumeral>
#endif
{
private static Func<TNumeral, TNumeral>? operationFunction = null!;
/// <summary>
/// Gets or sets the numeral value that will be incremented.
/// </summary>
[RequiredArgument]
public InOutArgument<TNumeral> Numeral { get; set; } = new();
/// <inheritdoc/>
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
UnaryExpressionHelper.OnGetArguments(metadata, Numeral);
EnsureOperationFunction(metadata, ref operationFunction!, ExpressionType.Decrement);
}
private static void EnsureOperationFunction
(
CodeActivityMetadata metadata,
ref Func<TNumeral, TNumeral> operationFunction,
ExpressionType operatorType
)
{
if (operationFunction is null)
{
if (!UnaryExpressionHelper.TryGenerateLinqDelegate(operatorType, out operationFunction!, out ValidationError? validationError))
{
metadata.AddValidationError(validationError);
}
}
}
/// <inheritdoc/>
protected override TNumeral Execute(CodeActivityContext context)
{
TNumeral value = Numeral.Get(context);
return operationFunction!.Invoke(value);
}
}
}