Ignore some certain properties when serialized. #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our project,each fields and properties whose modifier is PUBLIC will be serialized as a string format.Of course,we could modify their modifier to INTERNAL ,even PRIVATE,to prevent to serialize the fields or properties you don't really want.But in some certain situations you must to make a data modified as PUBLIC,we can also use the following changes.
I added a custom attribute("NonToJsonAttribute") in project,and use reflection to avoid adding fields or attributes to a serialized collection.By this way,every fields and properties that marked with "NonToJson" attribute will not be serialized.
Below is the example-code:
interface ITest
{
int TestProperty { get; }
}
class Test : ITest
{
//The property what I want not to serialize
[NonToJson]
public int TestProperty => 0;
public int Other { get; set; } = 1;
}