forked from JSONAPIdotNET/JSONAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelProperty.cs
More file actions
68 lines (60 loc) · 2.12 KB
/
Copy pathModelProperty.cs
File metadata and controls
68 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Linq;
using System.Reflection;
namespace JSONAPI.Core
{
/// <summary>
/// Stores a model's property and its usage.
/// </summary>
public abstract class ModelProperty
{
internal ModelProperty(PropertyInfo property, string jsonKey, bool ignoreByDefault)
{
IgnoreByDefault = ignoreByDefault;
JsonKey = jsonKey;
Property = property;
}
/// <summary>
/// The PropertyInfo backing this ModelProperty
/// </summary>
public PropertyInfo Property { get; private set; }
/// <summary>
/// The key that will be used to represent this property in JSON API documents
/// </summary>
public string JsonKey { get; private set; }
/// <summary>
/// Whether this property should be ignored by default for serialization.
/// </summary>
public bool IgnoreByDefault { get; private set; }
}
/// <summary>
/// A ModelProperty representing a flat field on a resource object
/// </summary>
public sealed class FieldModelProperty : ModelProperty
{
internal FieldModelProperty(PropertyInfo property, string jsonKey, bool ignoreByDefault)
: base(property, jsonKey, ignoreByDefault)
{
}
}
/// <summary>
/// A ModelProperty representing a relationship to another resource
/// </summary>
public class RelationshipModelProperty : ModelProperty
{
internal RelationshipModelProperty(PropertyInfo property, string jsonKey, bool ignoreByDefault, Type relatedType, bool isToMany)
: base(property, jsonKey, ignoreByDefault)
{
RelatedType = relatedType;
IsToMany = isToMany;
}
/// <summary>
/// The type of resource found on the other side of this relationship
/// </summary>
public Type RelatedType { get; private set; }
/// <summary>
/// Whether the property represents a to-many (true) or to-one (false) relationship
/// </summary>
public bool IsToMany { get; private set; }
}
}