diff options
author | JamesNK <james@newtonking.com> | 2009-05-09 14:19:32 +0400 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2009-05-09 14:19:32 +0400 |
commit | 3b26adfdd121e8861ae8a49f85014a3027b36cbb (patch) | |
tree | 7dacd213da69898f170380d535df9a89e1c67330 /Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs | |
parent | a0a8599d3de18b30b34f9836057c3336b4fb45eb (diff) |
-Added support for DataContractAttribute and DataMemberAttribute to JsonSerializer
-Added support for serializing private members by marking them with JsonPropertyAttribute or DataMemberAttribute
Diffstat (limited to 'Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs')
-rw-r--r-- | Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs new file mode 100644 index 0000000..878f629 --- /dev/null +++ b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs @@ -0,0 +1,34 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json.Serialization
+{
+ internal static class CachedAttributeGetter<T> where T : Attribute
+ {
+ private static readonly Dictionary<ICustomAttributeProvider, T> TypeAttributeCache = new Dictionary<ICustomAttributeProvider, T>();
+
+ public static T GetAttribute(ICustomAttributeProvider type)
+ {
+ T attribute;
+
+ if (TypeAttributeCache.TryGetValue(type, out attribute))
+ return attribute;
+
+ // double check locking to avoid threading issues
+ lock (TypeAttributeCache)
+ {
+ if (TypeAttributeCache.TryGetValue(type, out attribute))
+ return attribute;
+
+ attribute = JsonTypeReflector.GetAttribute<T>(type);
+ TypeAttributeCache[type] = attribute;
+
+ return attribute;
+ }
+ }
+ }
+}
|