Microsoft在BizTalk管道接口中提供了如下所示的验证组件。
以下是我尝试过的,但似乎一点也不管用:
public System.Collections.IEnumerator Validate(object projectSystem)
{
System.Collections.ArrayList errorStringArrayList = new System.Collections.ArrayList();
if (this.Substring1ColumnStart >= this.Substring1ColumnEnd)
{
errorStringArrayList.Add("Substring1ColumnEnd must be > SubstringColumn1Start");
}
return (System.Collections.IEnumerator) errorStringArrayList;
}他说
这些错误消息显示为编译器错误消息。要报告成功的属性验证,该方法应返回一个空枚举数。
。
但是当我输入无效的值时,我不会收到任何编译器消息。另外,在BTS-Admin中,如果没有“编译器消息”,它也不会进行验证吗?
此外,为什么验证作为parm而不是强类型parm接收泛型对象?验证什么时候被调用?每次更改propertyBag值?
更新2017年11月5日上午11时55分CT
我又尝试了几件事,其中两件很难在这里列出。我终于得到了一个错误,但在VS编译错误中不是一个非常有用的错误,请参见下面的屏幕快照。这绝对不是我返回的错误。也许这在VS2015上有问题。

我还遇到了一个问题,我修复了我的数据,但仍然得到了错误。因为管道组件是GAC‘’ed的,所以我每次都关闭并重新打开Visual,以确保它得到了新的副本。
我在想,也许除了返回null之外,其他任何东西都是问题所在。总之,如果它在BTS-ADMIN中不起作用,我发现它实际上是无用的。所以我只会做运行时错误。也许这就是为什么有这么少的文档和很少的文章/博客关于这个主题。
public System.Collections.IEnumerator Validate(object projectSystem)
{
System.Collections.ArrayList errorStringArrayList = new System.Collections.ArrayList();
if (this.Substring1ColumnStart >= this.Substring1ColumnEnd)
{
errorStringArrayList.Add("Substring1ColumnEnd must be > SubstringColumn1Start");
}
if (errorStringArrayList.Count > 0)
{
return (System.Collections.IEnumerator)errorStringArrayList;
}
else
{
return null;
}
}发布于 2017-05-10 18:32:49
这种验证方法仅在流水线设计模式下调用。它不会在BTS管理中被调用。如果您在“代码”中设置了一些无效的值。此方法也不被调用。
发布于 2017-05-11 14:29:51
来自MSDN的相同答案
从记忆中,但我93%肯定这就是它的工作方式..。
Visual在构建时以及可能在每个属性分配之后调用called。
如果返回非0集合,并且设计图面上的组件将具有红色的轮廓,则项目将不会生成。
IIRC,您只需直接验证属性值。IPropertyBag.Write已经被调用,您的代码应该已经设置了属性。
基本上,if(MyComponent.MySpecialValue != "B") {ErrorStringArray.Add(“噢不!”);}
https://stackoverflow.com/questions/43897650
复制相似问题