Example #1
0
        /// <summary>
        /// Emits the property values filtered by the given keyvalue filter.
        /// </summary>
        /// <typeparam name="TKey">The type of the keys.</typeparam>
        /// <typeparam name="TValue">The type of the values.</typeparam>
        /// <param name="Properties">An object implementing IReadOnlyProperties&lt;TKey, TValue&gt;.</param>
        /// <param name="KeyValueFilter">An optional delegate for keyvalue filtering.</param>
        /// <returns>The property values of the given property keys.</returns>
        public static PropertiesPipe <TKey, TValue> Ps <TKey, TValue>(this IReadOnlyProperties <TKey, TValue> Properties,
                                                                      KeyValueFilter <TKey, TValue> KeyValueFilter)

            where TKey : IEquatable <TKey>, IComparable <TKey>, IComparable
        {
            return(new PropertiesPipe <TKey, TValue>(Properties, KeyValueFilter));
        }
Example #2
0
        public static bool TryGetValue <T>(this IReadOnlyProperties <string, object> properties, string name, out T value)
        {
            var exists = properties.TryGetValue(name, out var result);

            value = exists && result != null ? (T)result : default;
            return(exists);
        }
Example #3
0
        /// <summary>
        /// Emits the property values of the given property keys (OR-logic).
        /// </summary>
        /// <typeparam name="TKey">The type of the keys.</typeparam>
        /// <typeparam name="TValue">The type of the values.</typeparam>
        /// <param name="Properties">An object implementing IReadOnlyProperties&lt;TKey, TValue&gt;.</param>
        /// <param name="Keys">An array of property keys.</param>
        /// <returns>The property values of the given property keys.</returns>
        public static PropertiesPipe <TKey, TValue> Ps <TKey, TValue>(this IReadOnlyProperties <TKey, TValue> Properties,
                                                                      params TKey[] Keys)

            where TKey : IEquatable <TKey>, IComparable <TKey>, IComparable

        {
            return(new PropertiesPipe <TKey, TValue>(Properties, Keys: Keys));
        }
Example #4
0
        /// <summary>
        /// Emits the property values filtered by the given keyvalue filter.
        /// </summary>
        /// <param name="SourcePipe">A pipe as element source.</param>
        /// <param name="KeyValueFilter">An optional delegate for keyvalue filtering.</param>
        public PropertiesPipe(IReadOnlyProperties <TKey, TValue> SourceElement,
                              KeyValueFilter <TKey, TValue> KeyValueFilter)

            : base(SourceElement)

        {
            this.KeyValueFilter = (KeyValueFilter != null) ? KeyValueFilter : (k, v) => true;
        }
Example #5
0
        /// <summary>
        /// Emits the property values of the given property keys (OR-logic).
        /// </summary>
        /// <param name="SourcePipe">A pipe as element source.</param>
        /// <param name="Keys">The property keys.</param>
        /// <returns>The property values of the given property keys.</returns>
        public PropertiesPipe(IReadOnlyProperties <TKey, TValue> SourceElement,
                              params TKey[]                      Keys)

            : base(SourceElement)

        {
            this.Keys = Keys;
        }
Example #6
0
        /// <summary>
        /// Emits the property values of the given property keys (OR-logic).
        /// </summary>
        /// <typeparam name="TKey">The type of the keys.</typeparam>
        /// <typeparam name="TValue">The type of the values.</typeparam>
        /// <param name="Properties">An object implementing IReadOnlyProperties&lt;TKey, TValue&gt;.</param>
        /// <param name="Keys">An array of property keys.</param>
        /// <returns>The property values of the given property keys.</returns>
        public static IDictionary <TKey, IEnumerable <TValue> > PMap <TKey, TValue>(this IReadOnlyProperties <TKey, TValue> Properties,
                                                                                    params TKey[] Keys)

            where TKey : IEquatable <TKey>, IComparable <TKey>, IComparable

        {
            var _Lookup = new Dictionary <TKey, IEnumerable <TValue> >();

            foreach (var Key in Keys)
            {
                _Lookup.Add(Key, new List <TValue>()
                {
                    Properties[Key]
                });
            }

            return(_Lookup);
        }
Example #7
0
        /// <summary>
        /// Emits the property values filtered by the given keyvalue filter.
        /// </summary>
        /// <typeparam name="TKey">The type of the keys.</typeparam>
        /// <typeparam name="TValue">The type of the values.</typeparam>
        /// <param name="Properties">An object implementing IReadOnlyProperties&lt;TKey, TValue&gt;.</param>
        /// <param name="KeyValueFilter">An optional delegate for keyvalue filtering.</param>
        /// <returns>The property values of the given property keys.</returns>
        public static IDictionary <TKey, IEnumerable <TValue> > PMap <TKey, TValue>(this IReadOnlyProperties <TKey, TValue> Properties,
                                                                                    KeyValueFilter <TKey, TValue> KeyValueFilter)

            where TKey : IEquatable <TKey>, IComparable <TKey>, IComparable
        {
            var _Lookup = new Dictionary <TKey, IEnumerable <TValue> >();

            foreach (var Property in Properties)
            {
                if (KeyValueFilter(Property.Key, Property.Value))
                {
                    _Lookup.Add(Property.Key, new List <TValue>()
                    {
                        Property.Value
                    });
                }
            }

            return(_Lookup);
        }
Example #8
0
        public static TResult SafeGet <TResult>(this IReadOnlyProperties <string, object> properties, string name)
        {
            var exists = properties.TryGetValue <TResult>(name, out var value);

            return(exists ? value : default);