using System;
using Apolyton.FastJson.Registry;
namespace Apolyton.FastJson.Registry
{
/// <summary>
/// Represents the internal property info.
/// </summary>
internal struct JsonPropertyInfo
{
/// <summary>
/// The empty instance.
/// </summary>
internal static JsonPropertyInfo Empty = new JsonPropertyInfo();
/// <summary>
/// Specifies the type of the member.
/// </summary>
public Type PropertyOrFieldType;
/// <summary>
/// Represents the non-nullable value behind the primary type. Normally, a cast of a value to the primary type should be possible.
/// </summary>
/// <example>
/// typeof(Double?) for instance is Nullable{double} with NullableType = typeof(double).
/// </example>
public Type NullableType;
/// <summary>
/// Represents the first item type for generic enumerations and collections (relevant for performance).
/// </summary>
public Type GenericItemType;
/// <summary>
/// Represents all generic types of the Primary Type.
/// </summary>
public Type[] GenericTypes;
/// <summary>
/// Specifies the property of field name.
/// </summary>
public string PropertyOrFieldName;
/// <summary>
/// Specifies the json field name for the given property.
/// </summary>
public string JsonFieldName;
/// <summary>
/// True, if member type is a dictionary.
/// </summary>
public bool IsDictionary;
/// <summary>
/// Determines, if member type is value type.
/// </summary>
public bool IsValueType;
/// <summary>
/// Determines, if the type is a generic type.
/// </summary>
public bool IsGenericType;
/// <summary>
/// Determines, if the member type is an array.
/// </summary>
public bool IsArray;
/// <summary>
/// Determines, if the member type is a byte array.
/// </summary>
public bool IsByteArray;
/// <summary>
/// Detemines, if the member type is a guid.
/// </summary>
public bool IsGuid;
/// <summary>
/// Determines, if the member type is a data set.
/// </summary>
public bool IsDataSet;
/// <summary>
/// Determines, if the member type is a data table.
/// </summary>
public bool IsDataTable;
/// <summary>
/// Determines, if the member type is a hash table.
/// </summary>
public bool IsHashtable;
/// <summary>
/// Determines, if the member type is an Enum.
/// </summary>
public bool IsEnum;
/// <summary>
/// Determines, if the member type is a date time.
/// </summary>
public bool IsDateTime;
/// <summary>
/// Determines the date time format a particular field is supposed to be implemented.
/// </summary>
public String DateTimeFormat;
/// <summary>
/// Determines, if the date kind of the member. Relevant for deserialization to now, if time zone adjustment is desired or not.
/// Defined through the JsonDateTimeOptions attribute.
/// </summary>
public DateTimeKind DateTimeKind;
/// <summary>
/// Determines, if the member type is an int.
/// </summary>
public bool IsInt;
/// <summary>
/// Determines, if the member type is a long.
/// </summary>
public bool IsLong;
/// <summary>
/// Determines, if the member type is a string.
/// </summary>
public bool IsString;
/// <summary>
/// Determines, if the member type is a bool.
/// </summary>
public bool IsBool;
/// <summary>
/// Determines, if the member type is a class.
/// </summary>
public bool IsClass;
/// <summary>
/// Determines, if the member type is a string dictionary.
/// </summary>
public bool IsStringDictionary;
/// <summary>
/// Represents a fast set function for the property or field.
/// </summary>
public GenericSetterHandler Setter;
/// <summary>
/// Represents a fast get function for the property or field.
/// </summary>
public GenericGetterHandler Getter;
/// <summary>
/// Determines, if the member type is a custom type.
/// </summary>
public bool IsCustomType;
/// <summary>
/// Determines, if the member type can be written to.
/// </summary>
public bool CanWrite;
/// <summary>
/// Specifies the default value of the property. For nullable types it is 'null', for other types determined throught the activator.
/// </summary>
public object DefaultValue;
/// <summary>
/// Returns true, if the references are equal.
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool operator ==(JsonPropertyInfo a, JsonPropertyInfo b)
{
return Object.ReferenceEquals(a, b);
}
/// <summary>
/// Returns true, if the references are not equal.
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool operator !=(JsonPropertyInfo a, JsonPropertyInfo b)
{
return !(a == b);
}
/// <summary>
/// Returns the hash code.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Returns true, if the objects are equal.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
return base.Equals(obj);
}
/// <summary>
/// Returns a lightweight object, which describes the serialization criteria.
/// </summary>
/// <returns></returns>
internal JsonSerializationInfo ToSerializationInfo()
{
JsonSerializationInfo info = new JsonSerializationInfo();
info.JsonFieldName = JsonFieldName;
info.MemberName = PropertyOrFieldName;
info.MemberType = PropertyOrFieldType;
if (GenericTypes == null)
{
info.MemberDisplayType = PropertyOrFieldType.Name;
}
else
{
info.MemberDisplayType = String.Format("{0}<{1}>", PropertyOrFieldType.Name, GenericTypes[0].Name);
}
return info;
}
/// <summary>
/// Returns a more meaningful string representing the info object.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return String.Format("{0}: {1}", PropertyOrFieldName, PropertyOrFieldType);
}
}
}