我不明白这条消息试图告诉我什么:
CodeContracts: invariant unproven: _uiRoot != null && _uiRoot.Children != null && _uiRoot.RowDefinitions != null && _uiRoot.ColumnDefinitions != null
这是方法:
private void AddRowToGrid(List<UIElement> row) {
Contract.Requires(row != null);
_uiRoot.RowDefinitions.Add(new RowDefinition());
VerifyColumnCount(row.Count);
int colunmn = 0;
foreach (UIElement uiElement in row.Where(element => element != null))
{
if (uiElement != null)
{
uiElement.SetValue(Grid.ColumnProperty, colunmn++);
if (_uiRoot.RowDefinitions != null)
{
uiElement.SetValue(Grid.RowProperty, _uiRoot.RowDefinitions.Count - 1);
if (_uiRoot.Children != null)
{
_uiRoot.Children.Add(uiElement);
}
}
}
}
}
这是不变量:
[ContractInvariantMethod]
private void ObjectInvariant() {
Contract.Invariant(_layoutList != null && this._layoutList.DefaultLayoutItemEntities != null);
Contract.Invariant(_uiRoot != null && _uiRoot.Children != null && _uiRoot.RowDefinitions != null &&
_uiRoot.ColumnDefinitions != null);
Contract.Invariant(_dragDropManager != null);
}
我尝试添加以下 Contract.Ensures,但它仍然给我同样的信息:
Contract.Ensures(_uiRoot != null && _uiRoot.Children != null && _uiRoot.RowDefinitions != null &&
_uiRoot.ColumnDefinitions != null);