private ContextualSerializerLookupKey GetKeyFromStorage(ContextTypeFlags flags, Type t) { lock (syncObj) { if (CachedKeyStore.ContainsKey(t)) { if (CachedKeyStore[t].ContainsKey(flags)) { return(CachedKeyStore[t][flags]); } else { return(CachedKeyStore[t][flags] = new ContextualSerializerLookupKey(flags, NoContextKey.Value, t)); } } else { CachedKeyStore.Add(t, new Dictionary <ContextTypeFlags, ContextualSerializerLookupKey>()); return(GetKeyFromStorage(flags, t)); } } }
/// <inheritdoc /> public ITypeSerializerStrategy Get(ContextualSerializerLookupKey key) { //If they ask for none it's best to just call general if (key.ContextFlags == ContextTypeFlags.None) { return(Get(key.ContextType)); } if (strategyLookupTable.ContainsKey(key)) { return(strategyLookupTable[key]); } if (isCompiled) { throw new InvalidOperationException($"Requested contextual serializer for Type: {key.ContextType} with but none were registered with Key: {key.ContextFlags} {key.ContextSpecificKey.Key}."); } //Return a lazy loaded version if it doesn't exist ContextualLazyStrategyProvider lazyProvider = new ContextualLazyStrategyProvider(this, key); return(Activator.CreateInstance(typeof(LazyLoadedSerializerStrategy <>).MakeGenericType(key.ContextType), SerializationContextRequirement.Contextless, key.ContextType, lazyProvider) as ITypeSerializerStrategy); }
public ContextKeyOverrideDecorator([NotNull] ISerializableTypeContext context, ContextualSerializerLookupKey key) { if (context == null) { throw new ArgumentNullException(nameof(context)); } managedContext = context; BuiltContextKey = key; }
public ContextualLazyStrategyProvider(IContextualSerializerProvider provider, ContextualSerializerLookupKey key) { SerializerStrategy = new Lazy <ITypeSerializerStrategy>(() => provider.Get(key), true); }
/// <inheritdoc /> public bool HasSerializerFor(ContextualSerializerLookupKey key) { return(strategyLookupTable.ContainsKey(key)); }
public static ISerializableTypeContext Override([NotNull] this ISerializableTypeContext context, ContextualSerializerLookupKey key) { if (context == null) { throw new ArgumentNullException(nameof(context)); } //Deocrate the context to set the provided key return(new ContextKeyOverrideDecorator(context, key)); }