You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are just quality of life improvements for developers. Although the language has support for myNumber++ and myNumber += anotherNumber, UiPath has no way to use these directly. The best we have currently is to use the Assign activity and manually add the correct number.
An AddAssign and Increment expression would be the first step in promoting this functionality in UiPath. The following are sample implementations of these expressions from my own code base. I multitarget from net462 up through net7.0, hence the ifdefs, which may be excluded in the official implementation (or included for whenever we update to Net7 or Net8). Nullable is enabled in this context, hence the null! declarations.
If this is something we are interested in, I am interested in implementing these features, though I'll break these out into two separate issues/PRs.
/// <summary>/// A code activity which increments a numeral./// </summary>/// <typeparam name="TNumeral">A numeric value, such as <see langword="int"/> or <see langword="long"/>.</typeparam>publicsealedclassIncrement<TNumeral>:CodeActivity<TNumeral>
#if NET7_0_OR_GREATER
whereTNumeral:INumber<TNumeral>
#endif
{privatestaticFunc<TNumeral,TNumeral>operationFunction=null!;/// <summary>/// Gets or sets the numeral value that will be incremented./// </summary>[RequiredArgument][DefaultValue(null)]publicInOutArgument<TNumeral>Numeral{get;set;}=null!;/// <inheritdoc/>protectedoverridevoidCacheMetadata(CodeActivityMetadatametadata){BinaryExpressionHelper.OnGetArguments(metadata,Numeral);Increment<TNumeral>.EnsureOperationFunction(metadata,refoperationFunction,ExpressionType.Increment);}privatestaticvoidEnsureOperationFunction(CodeActivityMetadatametadata,refFunc<TNumeral,TNumeral>operationFunction,ExpressionTypeoperatorType){if(operationFunction==null){if(!BinaryExpressionHelper.TryGenerateUnaryDelegate(operatorType,outoperationFunction!,outValidationError?validationError)){metadata.AddValidationError(validationError);}}}/// <inheritdoc/>protectedoverrideTNumeralExecute(CodeActivityContextcontext){TNumeralvalue=Numeral.Get(context);returnoperationFunction.Invoke(value);}}
/// <summary>/// A code activity which incrementally assigns a numeral./// </summary>/// <example>/// int myNum = 5;/// myNum += 5; // 10./// </example>/// <typeparam name="TLeft">The operand to modify.</typeparam>/// <typeparam name="TRight">The operand with which to modify <typeparamref name="TLeft"/>.</typeparam>/// <typeparam name="TResult">The resulting type of hte operation.</typeparam>publicsealedclassAddAssign<TLeft,TRight,TResult>:CodeActivity<TResult>
#if NET7_0_OR_GREATER
whereTLeft:INumber<TLeft>whereTRight:INumber<TRight>whereTResult:INumber<TResult>
#endif
{privatestaticFunc<TLeft,TRight,TResult>checkedOperationFunction=null!;privatestaticFunc<TLeft,TRight,TResult>uncheckedOperationFunction=null!;/// <summary>/// Gets or sets the left operand which will be modified by this operation./// </summary>[RequiredArgument][DefaultValue(null)]publicInArgument<TLeft>Left{get;set;}=null!;/// <summary>/// Gets or sets the right operand which will be the modifier for this operation./// </summary>[RequiredArgument][DefaultValue(null)]publicInArgument<TRight>Right{get;set;}=null!;/// <summary>/// Gets or sets a value indicating whether this operation will happen in a checked or unchecked context./// </summary>[DefaultValue(true)]publicboolIsChecked{get;set;}=true;/// <inheritdoc/>protectedoverridevoidCacheMetadata(CodeActivityMetadatametadata){BinaryExpressionHelper.OnGetArguments(metadata,Left,Right);if(IsChecked){AddAssign<TLeft,TRight,TResult>.EnsureOperationFunction(metadata,refcheckedOperationFunction,ExpressionType.AddAssignChecked);}else{AddAssign<TLeft,TRight,TResult>.EnsureOperationFunction(metadata,refuncheckedOperationFunction,ExpressionType.AddAssign);}}privatestaticvoidEnsureOperationFunction(CodeActivityMetadatametadata,refFunc<TLeft,TRight,TResult>operationFunction,ExpressionTypeoperatorType){if(operationFunction==null){if(!BinaryExpressionHelper.TryGenerateLinqDelegate(operatorType,outoperationFunction,outValidationErrorvalidationError)){metadata.AddValidationError(validationError);}}}/// <inheritdoc/>protectedoverrideTResultExecute(CodeActivityContextcontext){TLeftleftValue=Left.Get(context);TRightrightValue=Right.Get(context);// If user changed checked flag between open and execution, an NRE may be thrown.// This is by design.returnIsChecked?checkedOperationFunction(leftValue,rightValue):uncheckedOperationFunction(leftValue,rightValue);}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
These are just quality of life improvements for developers. Although the language has support for
myNumber++
andmyNumber += anotherNumber
, UiPath has no way to use these directly. The best we have currently is to use the Assign activity and manually add the correct number.An AddAssign and Increment expression would be the first step in promoting this functionality in UiPath. The following are sample implementations of these expressions from my own code base. I multitarget from net462 up through net7.0, hence the ifdefs, which may be excluded in the official implementation (or included for whenever we update to Net7 or Net8). Nullable is enabled in this context, hence the
null!
declarations.If this is something we are interested in, I am interested in implementing these features, though I'll break these out into two separate issues/PRs.
Beta Was this translation helpful? Give feedback.
All reactions