コード例 #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);
        }
コード例 #2
0
 public static string ToTsvHeaderRow <T>(this T objToSerialize) where T : class
 {
     return(TsvFormatter.GetHeaderRow(typeof(T)));
 }
コード例 #3
0
        public static string ToTsv <T>(this IEnumerable <T> collectionToSerialize, bool includeHeaders = true) where T : class
        {
            var data = string.Join("", collectionToSerialize.Select(x => x.ToTsvDataRow()));

            return(includeHeaders ? string.Concat(TsvFormatter.GetHeaderRow(typeof(T)), data) : data);
        }
コード例 #4
0
        public static string ToTsvDataRow <T>(this T objToSerialize) where T : class
        {
            var properties = TsvFormatter.GetSerializablePropertiesInOrder(typeof(T));

            return(TsvFormatter.GetTsvRow(properties, objToSerialize));
        }