You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the only way to exclude (readonly) properties is by using DumpOptions.ExcludeProperties.
It excludes all properties matching the names in the to-dump-object(-tree).
There might be use cases, where this is not preferred.
Intended Use Case
Let say, you want to dump an object with a readonly property, my current approach to produce compilable output would be by using 'ExcludeProperties'
Add an string interpretation which might point to the exact property
e.g. "Expection.Result" of the to-dump Tester object
Disadvantage: The '.' of object separation is very c#-specific and might lead to confusions
ExcludeReadonlyProperties
Add this to the DumpOptions to auto exclude all properties, which are readonly.
Disadvantage 1: what is readonly? everything which hasn't a public setter? what about objects with protect setter?
Disadvantage 2: You might include some readonly properties in the console-output, but exclude the rest of readonly members - this leads to the initial problem
publicclassActualPropertyExcluder:IPropertyExcluder{publicboolShouldExcludeProperty(inobjectobj,instringpropertyName)=>(obj is Actual)&&propertyName== nameof(Actual.Result);}
ObjectDumper.Dump(tester, new DumpOptions(){
IndentChar ='\t',IndentSize=1,LineBreakChar= Environment.NewLine,DumpStyle= DumpStyle.CSharp,ExcludeProperties=new IPropertyExcluder[]{new ActualPropertyExcluder()}});
Advantage 1: The consumer can decide, which property should be excluded (depending on the use case)
Advantage 2: DumpOptions properties 'SetPropertiesOnly' could also be obsoleted
Disadvantage: Breaking Change when used ExcludeProperties with older versions
The text was updated successfully, but these errors were encountered:
Summary
Currently the only way to exclude (readonly) properties is by using DumpOptions.ExcludeProperties.
It excludes all properties matching the names in the to-dump-object(-tree).
There might be use cases, where this is not preferred.
Intended Use Case
Let say, you want to dump an object with a readonly property, my current approach to produce compilable output would be by using 'ExcludeProperties'
However, if you've a more complex object (tree), where property names are duplicated, this lead to 'all or nothing':
API Changes
I can think of three solutions for this
full qualified property names of the tree
Add an string interpretation which might point to the exact property
e.g. "Expection.Result" of the to-dump Tester object
Disadvantage: The '.' of object separation is very c#-specific and might lead to confusions
ExcludeReadonlyProperties
Add this to the DumpOptions to auto exclude all properties, which are readonly.
Disadvantage 1: what is readonly? everything which hasn't a public setter? what about objects with protect setter?
Disadvantage 2: You might include some readonly properties in the console-output, but exclude the rest of readonly members - this leads to the initial problem
Provide an interface for excluding
Something like
And an respective array on DumpOptions
So it could be used depending on the use case:
Advantage 1: The consumer can decide, which property should be excluded (depending on the use case)
Advantage 2: DumpOptions properties 'SetPropertiesOnly' could also be obsoleted
Disadvantage: Breaking Change when used ExcludeProperties with older versions
The text was updated successfully, but these errors were encountered: