I have 2 types: BaseQuestion
and Question
. Question
inherits some properties from BaseQuestion
. Now I have created a Web API to make a BaseQuestion
available. The Question
datatype has additional properties that I do not want to make available. I have a method that retrieves a Question
and my initial plan was to just implicitly upcast it to BaseQuestion
. I thought it would lose all extra properties that I do not want to make accessible and I could return it.
Well, it doesn't. This is what I do:
Question q = allQuestions[0];
BaseQuestion bq = q;
string type = bq.GetType().ToString();
The type of bq is still "Question". I cannot access the BaseQuestion properties, but I can still see them in the debugger and they are in the JSON output that I send to the client.
Any ideas on how I can "force" bq to be of type BaseQuestion
and not to have any properties that are defined in the subclass?