Beispiel #1
0
 // Read and store metadata about given type, for non-compiled serialization/deserialization
 // This only needs to be called once, on the very first serialization/deserialization call.
 public static TypeMetadata ReadTypeMetadata([NotNull] Type type)
 {
     if (type == null) throw new ArgumentNullException("type");
     TypeMetadata typeMeta;
     if (!TypeMetadataCache.TryGetValue(type, out typeMeta)) {
         // If meta cache does not contain this type yet, lock and double-check
         lock (TypeMetadataCache) {
             if (!TypeMetadataCache.TryGetValue(type, out typeMeta)) {
                 // If meta cache still does not contain this type, fetch info and store it in cache
                 typeMeta = new TypeMetadata(type);
                 TypeMetadataCache.TryAdd(type, typeMeta);
             }
         }
     }
     return typeMeta;
 }