2020-10-03 10:48:25 +00:00
|
|
|
using Elsa.Serialization.Extensions;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2019-07-25 15:13:18 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Models
|
|
|
|
|
{
|
2020-10-03 10:48:25 +00:00
|
|
|
public class Variables
|
2019-09-15 10:16:24 +00:00
|
|
|
{
|
2020-10-03 10:48:25 +00:00
|
|
|
public Variables()
|
2019-07-25 15:13:18 +00:00
|
|
|
{
|
2020-10-18 15:05:48 +00:00
|
|
|
Data = new JObject();
|
2019-07-25 15:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
public Variables(Variables other) : this(other.Data)
|
2019-07-25 15:13:18 +00:00
|
|
|
{
|
2019-09-15 10:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
public Variables(JObject data)
|
2019-09-15 10:16:24 +00:00
|
|
|
{
|
2020-10-03 10:48:25 +00:00
|
|
|
Data = data;
|
2019-07-25 15:13:18 +00:00
|
|
|
}
|
2019-09-15 10:16:24 +00:00
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
public JObject Data { get; set; }
|
|
|
|
|
|
|
|
|
|
public JToken? Get(string name) => Has(name) ? Data[name] : default;
|
2020-10-18 15:05:48 +00:00
|
|
|
public T Get<T>(string name) => Has(name) ? Data.Value<T>(name) : default!;
|
2019-10-31 20:31:18 +00:00
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
public Variables Set(string name, JToken value)
|
2019-10-31 20:31:18 +00:00
|
|
|
{
|
2020-10-03 10:48:25 +00:00
|
|
|
Data[name] = value;
|
2019-12-23 20:43:11 +00:00
|
|
|
return this;
|
2019-07-25 15:13:18 +00:00
|
|
|
}
|
2019-09-15 10:16:24 +00:00
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
public bool Has(string name) => Data.HasKey(name);
|
2019-07-25 15:13:18 +00:00
|
|
|
}
|
2018-10-15 19:33:06 +00:00
|
|
|
}
|