/// <inheritdoc /> public bool RegisterType(ContextTypeFlags contextFlags, IContextKey key, Type type, ITypeSerializerStrategy strategy) { if (type == null) { throw new ArgumentNullException(nameof(type), $"Provided argument {nameof(type)} is null."); } if (strategy == null) { throw new ArgumentNullException(nameof(strategy), $"Provided argument {nameof(strategy)} is null."); } if (key == null) { throw new ArgumentNullException(nameof(key), $"Provided argument {nameof(key)} is null."); } //Check if contextflags are none. We can skip everything and delegate to contextless if (contextFlags == ContextTypeFlags.None) { return(RegisterType(type, strategy)); } //Register a new contextless serializer strategyLookupTable.Add(new ContextualSerializerLookupKey(contextFlags, key, type), strategy); return(true); }
public CacheDebugEntry(IContextKey key, GlobalPersistentContext value) { this.Value = value; var fields = key.GetType().GetFields(Flags.InstanceAnyDeclaredOnly); for (int i = 0; i < fields.Length; i++) { switch (i) { case 0: this.Alpha = fields[i].GetValue(key).ToString(); break; case 1: this.Beta = fields[i].GetValue(key).ToString(); break; case 2: this.Delta = fields[i].GetValue(key).ToString(); break; case 3: this.Epsilon = fields[i].GetValue(key).ToString(); break; case 4: this.Gamma = fields[i].GetValue(key).ToString(); break; } } }
public bool Equals(IContextKey x, IContextKey y) { if (x.GetType() != y.GetType()) { return(false); } return(x.Key == y.Key); }
public ContextualSerializerLookupKey(ContextTypeFlags flags, [NotNull] IContextKey contextSpecificKey, [NotNull] Type type) { if (contextSpecificKey == null) { throw new ArgumentNullException(nameof(contextSpecificKey), $"Provided argument {nameof(contextSpecificKey)} is null."); } if (type == null) { throw new ArgumentNullException(nameof(type), $"Provided argument {type} is null."); } ContextType = type; ContextFlags = flags; ContextSpecificKey = contextSpecificKey; CachedToString = $"{this.ContextFlags.ToString()}-{this.ContextSpecificKey?.GetType()?.Name}-{this.ContextSpecificKey.Key}-{ContextType?.FullName}"; CachedHashCode = CachedToString.GetHashCode(); }
private GlobalPersistentContext <TValue> TryGetContext <TValue>(IContextKey key, out bool isNew) { GlobalPersistentContext context; if (this.EnableCaching && this.cache.TryGetValue(key, out context) && context is GlobalPersistentContext <TValue> ) { isNew = false; return((GlobalPersistentContext <TValue>)context); } else { isNew = true; GlobalPersistentContext <TValue> c = GlobalPersistentContext <TValue> .Create(); this.cache[key] = c; return(c); } }
public int GetHashCode(IContextKey obj) { return($"{obj?.GetType()}-{obj?.Key}".GetHashCode()); }
public bool Equals(IContextKey x, IContextKey y) { return(x?.GetType() == y?.GetType() && x?.Key == y?.Key); }
public int GetHashCode(IContextKey obj) => Key;
public static bool HasSerializerFor([NotNull] this IContextualSerializerProvider provider, ContextTypeFlags contextFlags, [NotNull] IContextKey key, [NotNull] Type type) { if (provider == null) { throw new ArgumentNullException(nameof(provider), $"Cannot call extension method on null {nameof(IContextualSerializerProvider)}"); } if (key == null) { throw new ArgumentNullException(nameof(key)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } if (!Enum.IsDefined(typeof(ContextTypeFlags), contextFlags)) { throw new ArgumentOutOfRangeException(nameof(contextFlags), "Value should be defined in the ContextTypeFlags enum."); } /*if (!Enum.IsDefined(typeof(ContextTypeFlags), contextFlags)) * throw new InvalidEnumArgumentException(nameof(contextFlags), (int) contextFlags, typeof(ContextTypeFlags));*/ return(provider.HasSerializerFor(new ContextualSerializerLookupKey(contextFlags, key, type))); }