Lets say I have business class:
public class Foo
{
public int Prop1 {get;set;}
public int Prop2 {get;set;}
public Foo(int prop1, int prop2)
{
this.Prop1 = prop1;
this.Prop2 = prop2;
}
public Foo()
{
throw new NotImplementedException();
}
}
The business class is only valid if both properties are set. Therefore I could ensure implementing the parameterless constructor and throw a NotImplementedException if someone tries to instanciate the class with the parameterless constructor.
But now I want to be able to serialize/deserialize my class. For the deserilization process I need the default constructor, which musn't throw the NotImplementedExeption anymore.
Is there a way to find out whether a create an instance of my class with the default constructor or whether the object is being deserialized?
Let's assume I have no valid default values for both properties.
How could I solve this situation?