Since no one came up with potential solutions, but the question still got some attention, I decided to let you know how I solved the problem:
Approach No. 1:
The script itself, which raised the original question, included a mobile application consisting of
- API data model classes (used to serialize to / from JSON and load / load from the REST backend service),
- DB data model classes (representing SQLite tables) and
- various ViewModel classes used for the MVVM style presentation layer
The API models and DB models were almost identical (with the exception of the attributes necessary for JSON serialization and SQLite OR collation), the only structural difference is that the properties representing date / time were of type string in the API classes and DateTimeOffset in the DB classes. After loading the data and before loading the data onto the backend, the API and database models were converted into each other using Automapper.
I simply removed the string to DateTimeOffset conversion from the Automapper configuration and modified the database data model classes so that DateTimeOffset values ββare represented as string , which means they are stored as formatted text in SQLite (fortunately, no date and time calculations at the database level were required) . Since JSON objects retrieved from the backend include time zone information, I can simply pass these values ββto the database model, thereby ensuring that the database tables always contain dates / times as fully formatted time and time strings, including time zone offset.
Conversion from string to DateTimeOffset now occurs when creating ViewModel classes from database data models. Obviously, this happens more often than before (when converting API models to database models), which leads to a little overhead, but I can live with it because I no longer need to worry about a SQLite data type problem.
Approach No. 2:
Since approach No. 1 is not applicable to all scenarios, I came up with an alternative solution based on the first of 4 possible solutions proposed in the original question, but with reduced manual effort:
I created a custom attribute [DateTimeOffsetSerialize] , which can be assigned to DateTimeOffset properties in SQLite data model classes, and a post-assembly task that decompiles the assembly after the assembly is completed, and scans all the classes in the assembly to find these marked properties, for each of these of the marked properties, a duplicate property of type string is automatically created that contains the original value of the serialized property, and this newly created string property will be used as a column of the SQLite table (the original DateTimeOffset property of the tagged with the [Ignore] attribute).
This solution is available as a NuGet package and is open source on GitHub (the GitHub page also contains detailed usage instructions).