Skip to content
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

Feature Request: Add support for MemoryPackUnion for non-abstract, non-interface classes. #332

Open
jsupnik-ext-sd opened this issue Sep 16, 2024 · 0 comments

Comments

@jsupnik-ext-sd
Copy link

Would it be a significant lift to add support for the MemoryPackUnion tag to non-abstract base classes? I've got a class hierarchy where there are specialized instances of a general class of objects, and often collections keep track of the general class of objects without worrying about the special instances. For example:

public class Employee {
public string FirstName {get; set;}
public string LastName {get; set;}
public float Salary {get; set;}
}

public class Manager : Employee {
public List Reports {get; set;}
}

public class Team {
public List Members {get; set;}
}

If I serialize a team where some members are employees, but some are employees who are also managers, when I deserialize, my list will only consist of employees, no managers anymore, because there's no way to add polymorphism.

It'd be possible to work around this by creating an IEmployee interface, but I'm working in a large code base where substituting all such usages would be a fair bit of manual labor, and also reduce the readability of the code only to serve the needs of MemoryPack and not the program's overall architecture.

If this solution is reasonable architecturally, I can contribute to implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant