using System;
using System.Linq;
using System.Reflection;
namespace JSONAPI.Core
{
///
/// Stores a model's property and its usage.
///
public abstract class ModelProperty
{
internal ModelProperty(PropertyInfo property, string jsonKey, bool ignoreByDefault)
{
IgnoreByDefault = ignoreByDefault;
JsonKey = jsonKey;
Property = property;
}
///
/// The PropertyInfo backing this ModelProperty
///
public PropertyInfo Property { get; private set; }
///
/// The key that will be used to represent this property in JSON API documents
///
public string JsonKey { get; private set; }
///
/// Whether this property should be ignored by default for serialization.
///
public bool IgnoreByDefault { get; private set; }
}
///
/// A ModelProperty representing a flat field on a resource object
///
public sealed class FieldModelProperty : ModelProperty
{
internal FieldModelProperty(PropertyInfo property, string jsonKey, bool ignoreByDefault)
: base(property, jsonKey, ignoreByDefault)
{
}
}
///
/// A ModelProperty representing a relationship to another resource
///
public class RelationshipModelProperty : ModelProperty
{
internal RelationshipModelProperty(PropertyInfo property, string jsonKey, bool ignoreByDefault, Type relatedType, bool isToMany)
: base(property, jsonKey, ignoreByDefault)
{
RelatedType = relatedType;
IsToMany = isToMany;
}
///
/// The type of resource found on the other side of this relationship
///
public Type RelatedType { get; private set; }
///
/// Whether the property represents a to-many (true) or to-one (false) relationship
///
public bool IsToMany { get; private set; }
}
}