I have coded a custom Simple Test Activity and got same result in NativeActivity and CodeActivity.
Questions:
[DefaultValue(“”)] is not working on strings, boolean, integer, custom object or enum? How to pre-fill the input field with a default value?
How to return the value when having a Boolean as a checkbox? “F” is always false.
In UIPath how to make a new object in “I” and “J”?
using System;
using System.Activities.Presentation.Metadata;
using System.Activities;
using System.ComponentModel;
namespace SimpleTestActivity
{
public class TestActivity : CodeActivity
{
[DefaultValue("A")]
public InArgument<string> A { get; set; }
[DefaultValue("B")]
public string B { get; set; }
[DefaultValue("B")]
public InArgument<MyEnum> C { get; set; }
[DefaultValue("C")]
public MyEnum D { get; set; }
[DefaultValue(true)]
public InArgument<bool> E { get; set; }
[DefaultValue(true)]
public bool F { get; set; }
[DefaultValue(42)]
public InArgument<int> G { get; set; }
[DefaultValue(24)]
public int H { get; set; }
//[DefaultValue(new CustomClass("A", 2))] ????
public InArgument<CustomClass> I { get; set; }
//[DefaultValue(?????)]
public CustomClass J { get; set; }
public OutArgument<string> output { get; set; }
protected override void Execute(CodeActivityContext context)
{
string result = string.Format(
"A={0}, B={1}, C={2}, D={3}, E={4}, F={5}, G={6}, H={7}, I={8}, J={9}, K={10}, L={11}"
, context.GetValue(this.A) + ", " + this.A.Get(context) + ", " + this.A + ";" + Environment.NewLine
, this.B + ";" + Environment.NewLine
, context.GetValue(this.C) + ", " + this.C.Get(context) + ", " + this.C + ";" + Environment.NewLine
, this.D + ";" + Environment.NewLine
, context.GetValue(this.E) + ", " + this.E.Get(context) + ", " + this.E + ";" + Environment.NewLine
, this.F + ";" + Environment.NewLine
, context.GetValue(this.G) + ", " + this.G.Get(context) + ", " + this.G + ";" + Environment.NewLine
, this.H + ";" + Environment.NewLine
, context.GetValue(this.I)?.ToString() + ", " + this.I.Get(context)?.ToString() + ", " + this.I?.ToString() + ";" + Environment.NewLine
, this.J?.ToString() + ";" + Environment.NewLine
, this.J?.K?.ToString() + ";" + Environment.NewLine
, this.J?.L.ToString()
);
this.output.Set(context, result);
}
}
public enum MyEnum
{
A,
B,
C
}
public class CustomClass
{
public CustomClass(string k, int l)
{
_k = k;
_l = l;
}
public override string ToString()
{
return "(" + _k + "," + _l + ")";
}
string _k;
public string K
{
get
{
return _k;
}
set
{
_k = value;
}
}
int _l;
public int L
{
get
{
return _l;
}
set
{
_l = value;
}
}
}
public class RegisterMetadata : IRegisterMetadata
{
public void Register()
{
}
}
}