using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
using DPumpHydr.WinFrmUI.WenSkin.Json.Utilities;
namespace DPumpHydr.WinFrmUI.WenSkin.Json.Serialization
{
///
/// Contract details for a used by the .
///
public abstract class JsonContract
{
internal bool IsNullable;
internal bool IsConvertable;
internal bool IsEnum;
internal Type NonNullableUnderlyingType;
internal ReadType InternalReadType;
internal JsonContractType ContractType;
internal bool IsReadOnlyOrFixedSize;
internal bool IsSealed;
internal bool IsInstantiable;
private List _onDeserializedCallbacks;
private IList _onDeserializingCallbacks;
private IList _onSerializedCallbacks;
private IList _onSerializingCallbacks;
private IList _onErrorCallbacks;
private Type _createdType;
///
/// Gets the underlying type for the contract.
///
/// The underlying type for the contract.
public Type UnderlyingType { get; private set; }
///
/// Gets or sets the type created during deserialization.
///
/// The type created during deserialization.
public Type CreatedType
{
get
{
return _createdType;
}
set
{
_createdType = value;
IsSealed = _createdType.IsSealed();
IsInstantiable = !_createdType.IsInterface() && !_createdType.IsAbstract();
}
}
///
/// Gets or sets whether this type contract is serialized as a reference.
///
/// Whether this type contract is serialized as a reference.
public bool? IsReference { get; set; }
///
/// Gets or sets the default for this contract.
///
/// The converter.
public JsonConverter Converter { get; set; }
internal JsonConverter InternalConverter { get; set; }
///
/// Gets or sets all methods called immediately after deserialization of the object.
///
/// The methods called immediately after deserialization of the object.
public IList OnDeserializedCallbacks
{
get
{
if (_onDeserializedCallbacks == null)
{
_onDeserializedCallbacks = new List();
}
return _onDeserializedCallbacks;
}
}
///
/// Gets or sets all methods called during deserialization of the object.
///
/// The methods called during deserialization of the object.
public IList OnDeserializingCallbacks
{
get
{
if (_onDeserializingCallbacks == null)
{
_onDeserializingCallbacks = new List();
}
return _onDeserializingCallbacks;
}
}
///
/// Gets or sets all methods called after serialization of the object graph.
///
/// The methods called after serialization of the object graph.
public IList OnSerializedCallbacks
{
get
{
if (_onSerializedCallbacks == null)
{
_onSerializedCallbacks = new List();
}
return _onSerializedCallbacks;
}
}
///
/// Gets or sets all methods called before serialization of the object.
///
/// The methods called before serialization of the object.
public IList OnSerializingCallbacks
{
get
{
if (_onSerializingCallbacks == null)
{
_onSerializingCallbacks = new List();
}
return _onSerializingCallbacks;
}
}
///
/// Gets or sets all method called when an error is thrown during the serialization of the object.
///
/// The methods called when an error is thrown during the serialization of the object.
public IList OnErrorCallbacks
{
get
{
if (_onErrorCallbacks == null)
{
_onErrorCallbacks = new List();
}
return _onErrorCallbacks;
}
}
///
/// Gets or sets the method called immediately after deserialization of the object.
///
/// The method called immediately after deserialization of the object.
[Obsolete("This property is obsolete and has been replaced by the OnDeserializedCallbacks collection.")]
public MethodInfo OnDeserialized
{
get
{
if (OnDeserializedCallbacks.Count <= 0)
{
return null;
}
return OnDeserializedCallbacks[0].Method();
}
set
{
OnDeserializedCallbacks.Clear();
OnDeserializedCallbacks.Add(CreateSerializationCallback(value));
}
}
///
/// Gets or sets the method called during deserialization of the object.
///
/// The method called during deserialization of the object.
[Obsolete("This property is obsolete and has been replaced by the OnDeserializingCallbacks collection.")]
public MethodInfo OnDeserializing
{
get
{
if (OnDeserializingCallbacks.Count <= 0)
{
return null;
}
return OnDeserializingCallbacks[0].Method();
}
set
{
OnDeserializingCallbacks.Clear();
OnDeserializingCallbacks.Add(CreateSerializationCallback(value));
}
}
///
/// Gets or sets the method called after serialization of the object graph.
///
/// The method called after serialization of the object graph.
[Obsolete("This property is obsolete and has been replaced by the OnSerializedCallbacks collection.")]
public MethodInfo OnSerialized
{
get
{
if (OnSerializedCallbacks.Count <= 0)
{
return null;
}
return OnSerializedCallbacks[0].Method();
}
set
{
OnSerializedCallbacks.Clear();
OnSerializedCallbacks.Add(CreateSerializationCallback(value));
}
}
///
/// Gets or sets the method called before serialization of the object.
///
/// The method called before serialization of the object.
[Obsolete("This property is obsolete and has been replaced by the OnSerializingCallbacks collection.")]
public MethodInfo OnSerializing
{
get
{
if (OnSerializingCallbacks.Count <= 0)
{
return null;
}
return OnSerializingCallbacks[0].Method();
}
set
{
OnSerializingCallbacks.Clear();
OnSerializingCallbacks.Add(CreateSerializationCallback(value));
}
}
///
/// Gets or sets the method called when an error is thrown during the serialization of the object.
///
/// The method called when an error is thrown during the serialization of the object.
[Obsolete("This property is obsolete and has been replaced by the OnErrorCallbacks collection.")]
public MethodInfo OnError
{
get
{
if (OnErrorCallbacks.Count <= 0)
{
return null;
}
return OnErrorCallbacks[0].Method();
}
set
{
OnErrorCallbacks.Clear();
OnErrorCallbacks.Add(CreateSerializationErrorCallback(value));
}
}
///
/// Gets or sets the default creator method used to create the object.
///
/// The default creator method used to create the object.
public Func