OmitAutoProperties 影响非自动 属性
OmitAutoProperties affects non auto property
我有一个 class 有 属性 这样的
public string Foo
{
get { return _foo; }
set
{
if (!string.Equals(_foo, value))
{
_foo= value;
OnPropertyChanged();
}
}
}
当我用 _fixture = new Fixture {OmitAutoProperties = true};
创建对象时,我希望它有值,但它是 null 并且 setter 永远不会命中。我错过了什么吗?
OmitAutoProperties
设置决定 writable property should be set or not:
Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.
因此,如果它是 true
,AutoFixture 不会尝试 设置任何 属性 值,这是设计使然。
这是设计使然。正如文档所述:
Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.
换句话说,在 AutoFixture 中,术语 auto-属性 指的是 AutoFixture 自动填充可写属性的功能。也许更好的词是 DoNotAutomaticallyPopulateProperties
.
我能理解混淆,因为在C#中,auto-属性也可以理解为Auto-Implemented Properties.
的意思
坦率地说,AutoFixture 的术语也许应该更加谨慎地选择,但这些年来,我认为以前从未引起过我的注意。
特别是在 OP Foo
中是可写的 属性,当您禁用 auto-properties 时,永远不会调用 setter .
我有一个 class 有 属性 这样的
public string Foo
{
get { return _foo; }
set
{
if (!string.Equals(_foo, value))
{
_foo= value;
OnPropertyChanged();
}
}
}
当我用 _fixture = new Fixture {OmitAutoProperties = true};
创建对象时,我希望它有值,但它是 null 并且 setter 永远不会命中。我错过了什么吗?
OmitAutoProperties
设置决定 writable property should be set or not:
Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.
因此,如果它是 true
,AutoFixture 不会尝试 设置任何 属性 值,这是设计使然。
这是设计使然。正如文档所述:
Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.
换句话说,在 AutoFixture 中,术语 auto-属性 指的是 AutoFixture 自动填充可写属性的功能。也许更好的词是 DoNotAutomaticallyPopulateProperties
.
我能理解混淆,因为在C#中,auto-属性也可以理解为Auto-Implemented Properties.
的意思坦率地说,AutoFixture 的术语也许应该更加谨慎地选择,但这些年来,我认为以前从未引起过我的注意。
特别是在 OP Foo
中是可写的 属性,当您禁用 auto-properties 时,永远不会调用 setter .