GithubHelp home page GithubHelp logo

Comments (2)

gregmeess avatar gregmeess commented on May 25, 2024

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.

vangogih avatar vangogih commented on May 25, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.