I'm using Stateprinter to print/compare my types. It works quite nicely, however, it does compare the actual type of each (sub) object instead of the declared type of the subobject.
An example:
class X {
string Foo;
int Bar;
}
interface IMyData {
public X MyConfig { get; }
}
Now, when calling:
var cfg = ConfigurationHelper.GetStandardConfiguration();
cfg.Add(new PublicFieldsAndPropertiesHarvester());
var printer = new Stateprinter(cfg);
// ...
IMyData v = new MyDataWithMoreStuff();
printer.PrintObject(v);
This will print all the public fields and properties of MyDataWithMoreStuff
instead of only the public state visible via IMyData
.
Is there a way to do this with Stateprinter, or if that is currently not implemented, is it even possible using C# reflection to walk the "member tree" of an arbitrary object and treat the fields not by the concrete types that they have at runtime, but by the (base / interface) types the variables are declared with?
Aucun commentaire:
Enregistrer un commentaire