Esempio n. 1
0
        public static T FromTsvRow <T>(this string tsvString) where T : new()
        {
            if (string.IsNullOrEmpty(tsvString))
            {
                return(default(T));
            }

            var tsvValues = tsvString.Split(Char.Parse(TsvConfig.Delimiter));
            var propsDic  = TsvFormatter.PropertyNamesDictionary(typeof(T));

            var obj   = new T();
            var type  = typeof(T);
            var index = 0;

            foreach (var p in propsDic.OrderBy(x => x.Key))
            {
                var value = TsvConfig.DeserialzeFnDictionary.ContainsKey(p.Value.Value)
                    ? TsvConfig.DeserialzeFnDictionary[p.Value.Value](tsvValues[index])
                    : TsvFormatter.GetValue(tsvValues[index], p.Value.Value);

                type.GetProperty(p.Value.Key).SetValue(obj, value);
                index++;
            }

            return(obj);
        }