If a flag IsAdmin, cast as AdminUser otherwise cast as NormalUser.
Was just curious about this but not sure how to do it. I do see that you can create a child object based on a table value and another table like:
SiteUser is from the table Site_User AdminUser is from the table Site_User and Admin_User when Site_User.IsAdmin = true
However, I was curious if you could do this:
If IsAdmin is true, cast as AdminUser otherwise cast as NormalUser where AdminUser : SiteUSer and NormalUser : SiteUser BUT there isn't a Admin_User table or Normal_User table. This is strictly a casting based off the same table and a column value. The types hold no additional information, just would be helpful for situations like:
SomeMethod(SiteUser someUser)
{
if(someUser is AdminUser)
{
...
}
else
{
...
}
}
Instead of:
SomeMethod(SiteUser someUser)
{
if(someUser.IsAdmin)
{
...
}
else
{
...
}
}
Now I realize this may not be the best example, but say the flag is a multiple value property so instead of:
SomeMethod(SiteUser someUser)
{
swith(someUser.Role)
{
case(1):
break;
case(2)
break;
}
}
Of course this just might be a bad idea anyhow, but was wondering if it is possible.