My question: how do I convert a list of abstract classes back into their original classes (the classes that extend the abstract class).
I have a backend that returns a list of classes (List of UserModels) that all extends an abstract class. something like this:
public abstract class UserModel
{
...
}
public abstract class ContactModel: UserModel
{
...
}
public abstract class AdminModel: UserModel
{
...
}
In my front-end (Angular) I have the same setup.
In C# I can simpely split those by saying var isAdmin = someModel is AdminModel;
.
But when I get this list of users in the front-end I don't know how to convert these models from their abstract class back into the original classes.
I tried:
const isAdmin = Object.keys(AdminModel).every(key => user.hasOwnProperty(key));
const admin = user as AdminModel;
=> returned true with both models
and
const isAdmin = user instanceof AdminModel;
const admin = user as AdminModel;
=> returned false with both models
I hope this is possible. Thanks.
> GetUsers() and a method in angular: getUsers(): Observable { return this.getRequest(url); }
– Joren Goossens Mar 16 '21 at 15:11