-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the parsers to fill POCOs with unknown/incorrect data #3050
Comments
After some discussion: If the parsers detect an anomaly, they do NOT set the backing field. Instead, they will leave it null and create an overflow entry containing the data. When calling a getter, we check for null on the property backing field. If the backing field is null and the overflow dict EXISTS (check lazy initialized backing field), we try to find ourself in the overflow. If successful, we infer the parser error from the data. (We could also create an error datatype for this, which would be a wrapper around what would otherwise be in the dictionary directly) For primitives: we stuff the value as found in the JsonValue (as if it were overflow) Choice where no choice allowed: We consider it an unknown element unless we find a performant way to implement this. |
The disadvantage of using a wrapper in the overflow is of course that we introduce one more layer of indirection, and this means we need to adjust the DeepCopy, IsExactly, Matches etc methods to also be able to work with overflow entries that are not Base, but some kind of wrapper. Andrzej suggested that this wrapper van be a Base subclass, but still, it's a special case. The charm of the solution Kas original proposed, without the wrappers, is its natural simplicity. We'd only need them to carry information that the parser knows, but the objectmodel does not have. If that is so, we might also use Annotations, so the parser can communicate this extra data (like positional info in the json/xml file). |
Discussing with Andrzej, we discovered that the most natural way for the parser to work is to a) check whether the property is known an correct -> use the generated IL setter. If not, use |
This is the design discussion of #2908. |
Just realized that we have to make sure we will not initialize the backing field as a side-effect of doing a lookup, so calling // first: somePoco has no overflow
somePoco.IsExactly(otherPoco);
// now: somePoco has an initialized (but empty) overflow
// this will now trigger slower lookups:
var x = somePoco.SomeElement; |
Summary of the design is here: https://github.com/FirelyTeam/firely-net-sdk/wiki/Attribute-validation-and-Overflow (in progress). |
Small note: we should also make sure SetValue clears the dictionary entry if a matching entry exists. |
When executing this task, you will need functionality in the parsers to "make up" the best (dynamic)type in case of unknown data. There is some code like that in the |
This also requires handling erroneous data in such a way that the errors are accurate when fetching the incorrectly filled properties.
Quick list of errors that SHOULD be handled by base (not the parsers) for reference:
The text was updated successfully, but these errors were encountered: