我正在尝试打印出一个实现TableEntity类的对象,而没有那些关于持久性应该被忽略的对象。我通常用于打印对象的方法是使用StatePrinter。
public class MyEntity : TableEntity
{
public string MyProperty { get; set; }
[IgnoreProperty]
public string MyIgnoredProperty { get; set; }
public override string ToString()
{
Stateprinter printer = new Stateprinter();
return printer.PrintObject(this);
}
}
尽管这对于任何类型的类都非常有效,但使用此MyEntity类,它也会打印MyIgnoredProperty。打印出对象时,是否有聪明的方法也可以忽略具有[IgnoredProperty]作为属性的属性?
You can configure what fields/properties the
Stateprinter
cares about by configuring what "field harvester" to use.Here's a simple field harvester that only returns public properties without the '
IgnoreProperty
' attribute.然后像这样使用它:
And the result of
new MyEntity().ToString()
is now