Esempio n. 1
0
        /// <summary>
        /// cons
        /// </summary>
        /// <param name="str">string must not be null</param>
        /// <param name="opts">options</param>
        /// <param name="tc">custom type converter; if supplied, we will try these converters prior to trying Convert.ChangeType, in order supplied.
        /// Supplied converters must support converting FROM string, for proper functionality.
        /// </param>
        public DynamicString(string str, DynamicStringOptions opts, ReadOnlyCollection <TypeConverter> tc = null)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            Str  = str;
            Opts = opts;
            CustomTypeConverters = tc;
        }
Esempio n. 2
0
        /// <summary>
        /// cons, given enumerable
        /// </summary>
        /// <param name="strings"></param>
        /// <param name="dso">conversion options</param>
        /// <param name="tc">custom type converter; if supplied, we will try these converters prior to trying Convert.ChangeType, in order supplied.
        /// Supplied converters must support converting FROM string. Any converters not supporting this will be ignored.
        /// </param>
        public DynamicStrings(IEnumerable <KeyValuePair <string, string> > strings, IEqualityComparer <string> comparer = null, DynamicStringOptions dso = DynamicStringOptions.None, IEnumerable <TypeConverter> tc = null)
        {
            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            comparer             = comparer ?? StringComparer.OrdinalIgnoreCase;
            CustomTypeConverters = tc?.Where(x => x.CanConvertFrom(typeof(string))).ToList().AsReadOnly();
            //for nulls the val will be direct null.
            Map = new ReadOnlyDictionary <string, DynamicString>(strings.ToDictionary(x => x.Key, x => x.Value != null ? new DynamicString(x.Value, dso, CustomTypeConverters) : null, comparer));
        }