C# 从uiTypeEditor获取/设置工作流变量
我已经创建了一个自定义ui编辑器来处理工作流变量值的设置。我想做的是能够在uieditor中获取为工作流设置的任何变量的值C# 从uiTypeEditor获取/设置工作流变量,c#,workflow-foundation,C#,Workflow Foundation,我已经创建了一个自定义ui编辑器来处理工作流变量值的设置。我想做的是能够在uieditor中获取为工作流设置的任何变量的值 public class MyCustomEditor : UITypeEditor { public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value){ IWindowsFormsEditorServic
public class MyCustomEditor : UITypeEditor
{
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value){
IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
IBuildDefinition buildDefinition = (IBuildDefinition)provider.GetService(typeof(IBuildDefinition));
// Variable set in the workflow metadata to use this ui editor
MyCustomVariable variable = value as MyCustomVariable;
// Tried getting it from the Process Parameters but the only thing in there was BuildSettings
var processParms = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
object obj;
processParms.TryGetValue("BuildSettings", out obj);
BuildSettings buildSettings = obj as BuildSettings;
// I want to be able to access other variable for the workflow, everything above works. But MyCustomVariable is set in the Metadata to use this editor. I want to get the value of another variable in the workflow as well
return variable;
}
}
我错了,当我查看ProcessParameters时,构建定义还没有保存,所以这就是为什么我只看到“BuildSettings”,一旦我在保存的构建定义上反序列化它们,我就可以看到所有变量
var processParms = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
object obj;
processParms.TryGetValue("MyOtherVariable", out obj);
MyOtherVariable myOtherVariable = obj as MyOtherVariable;
您是否尝试过使用BuildDefinition.Process.Parameters?IIRC该参数与BuildDefinition.ProcessParameters之间有细微的区别,后者仅在定义本身上重写。编辑BuildRequest时也可能显示编辑器。您还必须检查此处定义的流程参数。我刚刚尝试反序列化WorkflowHelpers.DeserializeProcessParametersBuildDefinition.process.parameters,但在类型上找不到匹配的构造函数,因此出现了一个错误。在尝试使用以下代码时,您可以使用参数或FactoryMethod指令来构造类型。@mikez我正确地看到了xml值,只需要知道如何获取当前值?好的,我必须弄清楚流程模板中是否定义了参数/变量,以便覆盖默认值。我只是使用XDocument来解析BuildDefinition.Process.Parameters并查找特定元素的存在性。也许您可以做类似的事情,如果参数值是一个基本类型,这可能很容易,但是如果它是一个自定义类型,这可能很困难。