1 //---------------------------------------------------------------- 2 // Copyright (c) Microsoft Corporation. All rights reserved. 3 //---------------------------------------------------------------- 4 5 namespace System.Activities.Expressions 6 { 7 using System.Activities; 8 using System.Activities.Validation; 9 using System.ComponentModel; 10 using System.Linq.Expressions; 11 using System.Runtime; 12 13 public sealed class GreaterThanOrEqual<TLeft, TRight, TResult> : CodeActivity<TResult> 14 { 15 //Lock is not needed for operationFunction here. The reason is that delegates for a given GreaterThanOrEqual<TLeft, TRight, TResult> are the same. 16 //It's possible that 2 threads are assigning the operationFucntion at the same time. But it's okay because the compiled codes are the same. 17 static Func<TLeft, TRight, TResult> operationFunction; 18 19 [RequiredArgument] 20 [DefaultValue(null)] 21 public InArgument<TLeft> Left 22 { 23 get; 24 set; 25 } 26 27 [RequiredArgument] 28 [DefaultValue(null)] 29 public InArgument<TRight> Right 30 { 31 get; 32 set; 33 } 34 CacheMetadata(CodeActivityMetadata metadata)35 protected override void CacheMetadata(CodeActivityMetadata metadata) 36 { 37 BinaryExpressionHelper.OnGetArguments(metadata, this.Left, this.Right); 38 39 if (operationFunction == null) 40 { 41 ValidationError validationError; 42 if (!BinaryExpressionHelper.TryGenerateLinqDelegate(ExpressionType.GreaterThanOrEqual, out operationFunction, out validationError)) 43 { 44 metadata.AddValidationError(validationError); 45 } 46 } 47 } 48 Execute(CodeActivityContext context)49 protected override TResult Execute(CodeActivityContext context) 50 { 51 Fx.Assert(operationFunction != null, "OperationFunction must exist."); 52 TLeft leftValue = this.Left.Get(context); 53 TRight rightValue = this.Right.Get(context); 54 return operationFunction(leftValue, rightValue); 55 } 56 } 57 } 58