If I have a complex object, can I inherit from it and remove or ignore certain properties?
If you don't care why I want to do this, feel free to just submit an answer.
If you do care, you can read this question. To summarize it, I have an object that has a single property that is not serializable, and I want to serialize the entire object. The object in question is System.Exception
To get around the problem I wanted to simply create my own JsonException
object, inherit all the lovely properties of the base (System.Exception
) except remove (or empty) the ugly duckling (Exception.TargetSite
).
Something like:
public class MyException : Exception
{
// Note this is not actually possible
// just demonstrating what I thought to do in theory
public override System.Reflection.MethodBase TargetSite
{
get
{
return null;
}
}
public MyException(string message)
: base()
{
}
}
Also please keep in mind I am stuck with .NET 2.0 and really don't want to use custom serializers (like Json.NET) if I don't have to.