-
Notifications
You must be signed in to change notification settings - Fork 14
Description
NetTopologySuite/NetTopologySuite.IO.GeoJSON#117 was a bit of an awkward spot.
I would have preferred to have pointed to an IsReadOnly property and recommended copying the read-only IAttributesTable into a new editable instance, since I don't expect there to be many actual use cases where you need to edit the table in-place. After all, the table itself is little more than a way for us to expose the data that's present in the source file, and any edits that you make to the table instance do not directly get written back to that source file.
However:
- No
IsReadOnlyproperty (or related thing) exists, and so a negative response would have been unfair: it's unreasonable that "you just have to know" that the 4STJ implementation ofIAttributesTableis read-only, especially when its Newtonsoft.Json counterpart did not work that way. - There is no simple, built-in way to take an existing
IAttributesTableinstance and use it to initialize a newIAttributesTableobject that's writable and has the same initial values, so even if had allowed myself to say "you just have to know", it would have still added an unreasonable amount of friction to the upgrade process, because a downstream consumer should not be expected to implement something like that on their own.
Things Not To Do... Yet...?
These would all be breaking changes:
- add
bool IsReadOnly { get; }directly to theIAttributesTableinterface - add
IAttributesTable ToWritable();directly to theIAttributesTableinterface - make an
IReadOnlyAttributesTableinterface, and changeIAttributesTableto extend it
Suggestions
- Create an
IReadOnlyAttributesTableinterface. Implement it in this project'sAttributesTableclass. When the new version of this library is published, implement that interface in the classes that implement this interface for all our other IO libraries. - Create a
public static AttributesTable ToWritable(this IAttributesTable @this)extension method that creates a new emptyAttributesTableand initializes it using values copied from@this.- Alongside this extension method, create a new interface, something like
ICanCopyToNewWritableAttributesTable(better name???). It only has one method:void CopyTo(AttributesTable table);. The extension method would check if@thisimplements that interface. If it does, then we call that method. Otherwise, we do the copying ourselves. As above, implement this interface in all of our own implementations ofIAttributesTable, for the best user experience.
- Alongside this extension method, create a new interface, something like
I'm intentionally not jumping on this right away, because I think there's some room for some better ideas, and/or it might be a good first issue for someone new. (edit to add:) ...also, I still hold on hope that something might eventually happen with #6, which would affect this... even though, realistically, it's probably too big a change for too small a benefit...