I have a class with a field that is a delegate that I would like to serialize and deserialize.
It looks like so:
public delegate bool DistanceEqualityStrategy (Distance distance1, Distance distance2);
[JsonObject(MemberSerialization.Fields)]
public partial class Distance
{
private double _intrinsicValue;
[JsonIgnore]
private DistanceEqualityStrategy _strategy;
public Distance(double passedInput, DistanceEqualityStrategy passedStrategy = null)
{
_intrinsicValue = passedInput;
_equalityStrategy = _chooseDefaultOrPassedStrategy(passedStrategy);
}
public Distance(Distance passedDistance)
{
_intrinsicValue = passedDistance._intrinsicValue;
_equalityStrategy = passedDistance._equalityStrategy;
}
private static DistanceEqualityStrategy _chooseDefaultOrPassedStrategy(DistanceEqualityStrategy passedStrategy)
{
if (passedStrategy == null)
{
return EqualityStrategyImplementations.DefaultConstantEquality;
}
else
{
return passedStrategy;
}
}
}
I am having trouble understanding what is really going on when deserializing this object. How does the object get rebuilt? Does it call a specific constructor of the class when it attempts to recreate the object? It serializes just fine, but when the object is rebuilt, it sets the delegate to be null.
This leads me to the conclusion that I do not understand how this deserialization works, as it does not seem to use a constructor.
Can someone explain to me how an object is created on deserialization without using the constructors?