GetVariable(string name, Type type) (#155)
* GetVariable(string name, Type type)
This commit is contained in:
parent
13b51f3e7c
commit
58d7bc654a
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
|
@ -29,10 +30,15 @@ namespace Elsa.Models
|
|||
return ContainsKey(name) ? this[name] : default;
|
||||
}
|
||||
|
||||
public object GetVariable(string name, Type type)
|
||||
{
|
||||
var value = ContainsKey(name) ? this[name] : default;
|
||||
return value == null ? default : value.ToObject(type);
|
||||
}
|
||||
|
||||
public T GetVariable<T>(string name)
|
||||
{
|
||||
var value = ContainsKey(name) ? this[name] : default;
|
||||
|
||||
return value == null ? default : value.ToObject<T>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace Elsa.Models
|
||||
{
|
||||
|
|
@ -18,6 +19,7 @@ namespace Elsa.Models
|
|||
}
|
||||
|
||||
public T GetVariable<T>(string name) => Variables.GetVariable<T>(name);
|
||||
public object GetVariable(string name, Type type) => Variables.GetVariable(name, type);
|
||||
public JToken GetVariable(string name) => Variables.GetVariable(name);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
|
@ -75,7 +75,14 @@ namespace Elsa.Services.Models
|
|||
var scope = Workflow.Scopes.FirstOrDefault(x => x.Variables.ContainsKey(name)) ?? CurrentScope;
|
||||
return scope.GetVariable<T>(name);
|
||||
}
|
||||
|
||||
|
||||
public object GetVariable(string name, Type type)
|
||||
{
|
||||
// Get the first scope (starting from the newest one) containing the variable.
|
||||
var scope = Workflow.Scopes.FirstOrDefault(x => x.Variables.ContainsKey(name)) ?? CurrentScope;
|
||||
return scope.GetVariable(name, type);
|
||||
}
|
||||
|
||||
public object GetVariable(string name)
|
||||
{
|
||||
// Get the first scope (starting from the newest one) containing the variable.
|
||||
|
|
|
|||
Loading…
Reference in a new issue