/// <summary> /// Registers this type /// </summary> /// <param name="encoding"></param> public void Register(PairEncodingDefinitionBase encoding) { if ((object)encoding == null) { throw new ArgumentNullException("encoding"); } lock (m_syncRoot) { if (encoding.KeyTypeIfNotGeneric == null && encoding.ValueTypeIfNotGeneric == null) { m_combinedEncoding.Add(encoding.Method, encoding); } else if (encoding.KeyTypeIfNotGeneric != null && encoding.ValueTypeIfNotGeneric == null) { m_keyTypedCombinedEncoding.Add(Tuple.Create(encoding.Method, encoding.KeyTypeIfNotGeneric), encoding); } else if (encoding.KeyTypeIfNotGeneric == null && encoding.ValueTypeIfNotGeneric != null) { m_valueTypedCombinedEncoding.Add(Tuple.Create(encoding.Method, encoding.ValueTypeIfNotGeneric), encoding); } else { m_keyValueTypedCombinedEncoding.Add(Tuple.Create(encoding.Method, encoding.KeyTypeIfNotGeneric, encoding.ValueTypeIfNotGeneric), encoding); } } }
/// <summary> /// Registers this type /// </summary> /// <param name="encoding"></param> public void Register(PairEncodingDefinitionBase encoding) { if (encoding is null) { throw new ArgumentNullException("encoding"); } lock (m_syncRoot) { if (encoding.KeyTypeIfNotGeneric is null && encoding.ValueTypeIfNotGeneric is null) { m_combinedEncoding.Add(encoding.Method, encoding); }
/// <summary> /// Registers the provided type in the encoding library. /// </summary> /// <param name="encoding">the encoding to register</param> internal void Register(PairEncodingDefinitionBase encoding) { m_doubleEncoding.Register(encoding); }
/// <summary> /// Attempts to get the specified encoding method from the dictionary. Will register the types if never registered before. /// </summary> /// <typeparam name="TKey">The key</typeparam> /// <typeparam name="TValue">The value</typeparam> /// <param name="encodingMethod">the encoding method</param> /// <param name="encoding">an output if the encoding method exists.</param> /// <returns>True if the encoding value was found, false otherwise.</returns> public bool TryGetEncodingMethod <TKey, TValue>(EncodingDefinition encodingMethod, out PairEncodingDefinitionBase encoding) where TKey : SnapTypeBase <TKey>, new() where TValue : SnapTypeBase <TValue>, new() { if ((object)encodingMethod == null) { throw new ArgumentNullException("encodingMethod"); } Type keyType = typeof(TKey); Type valueType = typeof(TValue); lock (m_syncRoot) { if (m_keyValueTypedCombinedEncoding.TryGetValue(Tuple.Create(encodingMethod, keyType, valueType), out encoding) || m_keyTypedCombinedEncoding.TryGetValue(Tuple.Create(encodingMethod, keyType), out encoding) || m_valueTypedCombinedEncoding.TryGetValue(Tuple.Create(encodingMethod, valueType), out encoding) || m_combinedEncoding.TryGetValue(encodingMethod, out encoding)) { return(true); } } return(false); }