Esempio n. 1
0
        public static Int32Key FindInt32KeyWithoutType(this KeyToParametersConverter converter, IReadOnlyKeyValueCollection parameters, string keyType)
        {
            Ensure.NotNull(converter, "converter");
            Int32Key key;

            if (converter.TryGetWithoutType(parameters, keyType, out key))
            {
                return(key);
            }

            return(Int32Key.Empty(keyType));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a key from the <paramref name="parameters"/> with <paramref name="prefix"/> and <see cref="IKey.Type"/> set to <paramref name="keyType"/> or throws <see cref="MissingKeyInParametersException"/>.
        /// </summary>
        /// <param name="converter">A key-parameters converter.</param>
        /// <param name="parameters">A collection of parameters.</param>
        /// <param name="prefix">A values prefix for <paramref name="parameters"/>.</param>
        /// <param name="keyType">A <see cref="IKey.Type"/> for key to create.</param>
        /// <returns>A key from the <paramref name="parameters"/> or throws <see cref="MissingKeyInParametersException"/>.</returns>
        public static IKey GetWithoutType(this KeyToParametersConverter converter, IReadOnlyKeyValueCollection parameters, string keyType, string prefix)
        {
            Ensure.NotNull(converter, "converter");
            IKey key;

            if (converter.TryGetWithoutType(parameters, keyType, prefix, out key))
            {
                return(key);
            }

            throw new MissingKeyInParametersException();
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a key from the <paramref name="parameters"/> or throws <see cref="MissingKeyInParametersException"/>.
        /// </summary>
        /// <param name="converter">A key-parameters converter.</param>
        /// <param name="parameters">A collection of parameters.</param>
        /// <returns>A key from the <paramref name="parameters"/> or throws <see cref="MissingKeyInParametersException"/>.</returns>
        public static IKey Get(this KeyToParametersConverter converter, IReadOnlyKeyValueCollection parameters)
        {
            Ensure.NotNull(converter, "converter");
            IKey key;

            if (converter.TryGet(parameters, out key))
            {
                return(key);
            }

            throw new MissingKeyInParametersException();
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a key from the <paramref name="parameters"/> with <paramref name="prefix"/> or throws <see cref="MissingKeyInParametersException"/>.
        /// </summary>
        /// <typeparam name="TKey">A type of the key.</typeparam>
        /// <param name="converter">A key-parameters converter.</param>
        /// <param name="parameters">A collection of parameters.</param>
        /// <param name="prefix">A values prefix for <paramref name="parameters"/>.</param>
        /// <returns>A key from the <paramref name="parameters"/> or throws <see cref="MissingKeyInParametersException"/>.</returns>
        public static TKey Get <TKey>(this KeyToParametersConverter converter, IReadOnlyKeyValueCollection parameters, string prefix)
            where TKey : IKey
        {
            Ensure.NotNull(converter, "converter");
            TKey key;

            if (converter.TryGet(parameters, prefix, out key))
            {
                return(key);
            }

            throw new MissingKeyInParametersException();
        }
 /// <summary>
 /// Adds default mappings to the <paramref name="converter"/> for <see cref="Int16Key"/>, <see cref="Int32Key"/>, <see cref="Int64Key"/>, <see cref="StringKey"/> and <see cref="GuidKey"/>.
 /// </summary>
 /// <param name="converter">A key-parameters converter.</param>
 /// <returns><paramref name="converter"/>.</returns>
 public static KeyToParametersConverter AddDefaultMapping(this KeyToParametersConverter converter)
 {
     Ensure.NotNull(converter, "converter");
     converter.Definitions.AddDefaultMapping();
     return(converter);
 }