工作流 3.5 活动属性在条件下为空,其他地方都为空

发布于 2024-09-16 09:55:19 字数 818 浏览 11 评论 0原文

我有一个活动,其属性看起来像这样(它们被设置为正确的依赖属性,我只是在这里保持简单):

public List<MyType> TypeList { get; set; }
public Int32 Index { get; set; }
public MyType SelectedType { get; set; }

并且执行就是这样做的:

SelectedType = TypeList[Index];

TypeList 和 Index 是我从其他活动设置的值。我没有将 SelectedType 设置为活动属性中的任何内容,只是让它在执行中设置。

现在我知道 SelectedType 已正确设置,我什至可以将另一个活动指向它并从中打印出一些值。所以我非常肯定这项活动没有任何问题。

但是,我有一个 if 活动,其条件如下所示:

((MyActivity)GetActivityByName("activity1")).SelectedType != null

并且它的计算结果为 false(意味着它将 SelectedType 计算为 null)。我非常确定该活动转换是正确的(我一直在做类似的事情),如果不是,我在尝试访问 SelectedType 时不会得到空引用异常吗?所以我很确定我在这里没有做任何错误,但由于某种原因 SelectedType 在这种情况下会出现 null,而在其他地方则不会。

这几乎就像在运行活动之前评估条件一样,但活动远远早于工作流中的条件,因此我不明白为什么会出现这种情况。

有人能解释一下吗?

I have an activity that has properties that look something like this (they're set up as proper dependency properties, I just kept it simple here):

public List<MyType> TypeList { get; set; }
public Int32 Index { get; set; }
public MyType SelectedType { get; set; }

and an execution that just does this:

SelectedType = TypeList[Index];

TypeList and Index are values that I set from other activities. I don't set SelectedType to anything in the activity properties, I just let it get set in the execution.

Now I know for a fact that SelectedType is getting set properly, I can even point another activity to it and print out some values from it. So I'm quite positive that there's nothing wrong with that activity.

However, I have an if activity with a condition that looks like this:

((MyActivity)GetActivityByName("activity1")).SelectedType != null

and it evaluates to false (meaning it evaluated SelectedType as null). I'm pretty sure that that activity cast is correct (I do things like that all the time), and if it weren't wouldn't I get a null reference exception when trying to access SelectedType? So I'm pretty sure I'm not doing anything wrong here, but for some reason SelectedType is coming up null in that condition and no where else.

It's almost as if the condition is being evaluated before the activity is being run, but the activity comes well before the condition in the workflow, so I don't see why that would be the case.

Can anyone shed some light on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

波浪屿的海角声 2024-09-23 09:55:19

显然,这与 while 循环导致活动被克隆有关。我通过将活动属性绑定到工作流属性来修复它。有关详细信息,请参阅 这篇文章,我在工作流程论坛上发布的。

Apparently it has to do with the while loop causing activities to be cloned. I fixed it by binding the activity property to workflow properties. For more info, see this post that I put up on the workflow forums.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文