-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathModelManager.cs
More file actions
50 lines (36 loc) · 1.2 KB
/
ModelManager.cs
File metadata and controls
50 lines (36 loc) · 1.2 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace JSONAPI.Core
{
public class ModelManager : IModelManager
{
public ModelManager() { }
#region Cache storage
private Lazy<Dictionary<Type, PropertyInfo>> _idProperties
= new Lazy<Dictionary<Type,PropertyInfo>>(
() => new Dictionary<Type, PropertyInfo>()
);
#endregion
#region Id property determination
public PropertyInfo GetIdProperty(Type type)
{
PropertyInfo idprop = null;
var idPropCache = _idProperties.Value;
lock (idPropCache)
{
if (idPropCache.TryGetValue(type, out idprop)) return idprop;
//TODO: Enable attribute-based determination
idprop = type.GetProperty("Id");
if (idprop == null)
throw new InvalidOperationException(String.Format("Unable to determine Id property for type {0}", type));
idPropCache.Add(type, idprop);
}
return idprop;
}
#endregion
}
}