Comments (2)
Another potential workaround that doesn't require changes: override the version number in the derived class, but call the appropriate migration methods from the parent class in the derived class migration method.
Example:
[Migratable("")]
public class ParentClass
{
public virtual int Version { get; } = 2;
protected static JObject Migrate_1(JObject data, JsonSerializer serializer)
{
// do migration
}
protected static JObject Migrate_2(JObject data, JsonSerializer serializer)
{
// do migration
}
}
[Migratable("")]
public class ChildClass : ParentClass
{
public virtual int Version { get; } = 3;
protected static JObject Migrate_1(JObject data, JsonSerializer serializer)
{
data = ParentClass.Migrate_1(data, serializer);
// do child class migration
}
protected static JObject Migrate_2(JObject data, JsonSerializer serializer)
{
// do child class migration that doesn't include up-revving parent class
}
protected static JObject Migrate_3(JObject data, JsonSerializer serializer)
{
data = ParentClass.Migrate_2(data, serializer);
// do child class migration
}
}
If I'm thinking through this correctly:
- Every time a parent class version increments, any derived classes also need to increment so that they can call the parent class migration.
- Child classes can increment version without the parent class being affected, so version numbers won't necessarily be the same between parent and child class.
- The onus is on the developer to manage version numbers in an inheritance hierarchy and make sure the appropriate migrations are getting called in derived classes.
from migrations.json.net.
@gregmeess hey mate,
I rewrote this plugin and made it from 5 to 10 times faster:
Link to plugin: https://github.com/vangogih/FastMigrations.Json.Net
According to your recommendations I wrote test cases to be support inheritance without pain)
Link to test case
Also you can check ParentMock
and ChildV10Mock
to check the structure and idea how we should add inheritance support while working with plugin.
It has been a while since your comment but I hope you will find the time to check it ;)
Don't hesitate to create an issue or PR!
Looking forward to getting feedback from you!
from migrations.json.net.
Related Issues (18)
- Support VS2015 and .Net 4.6 on build server HOT 1
- Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer cannot be created HOT 3
- NullReferenceException MigrationHashHelper HOT 2
- Documentation HOT 3
- Custom migrator
- Doesn't work with IL2Cpp HOT 4
- MigratableAttribute / [Migratable("xxxx")] HOT 1
- Verify migration HOT 1
- Migration breaks when using PreserveReferencesHandling HOT 2
- This plugin is outdated and unsupported
- Support nested migratable types HOT 1
- NuGet dependencies don't work
- Add more analyzers/code fixes HOT 1
- Check if test project compiles HOT 1
- Populating object that has read-only getter doesn't work
- Migration method verification is broken HOT 1
- Error when deserializing with PreserveReferencesHandling.Objects
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migrations.json.net.