コード例 #1
0
ファイル: Program.cs プロジェクト: Gabsamolis/EDI
        // Populate headers object
        public static List<fHdr> CreateHeader(string[] HFileContent, Dictionary<string, string> stores, Dictionary<string, string> coetType)
        {
            var mHdrs = new List<fHdr>();
            int i = 0;
            foreach (var headerLine in HFileContent)
            {
                var line = new fHdr();
                string[] token = headerLine.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (PropertyInfo prop in line.GetType().GetProperties())
                {
                    string t = prop.PropertyType.ToString();
                    switch (t)
                    {
                        case "System.String":
                            string tmps;
                            if (stores.ContainsKey(Convert.ToString(token[i])))
                                tmps = Convert.ToString(stores[Convert.ToString(token[i])]);
                            else if (coetType.ContainsKey(Convert.ToString(token[i])))
                                tmps = Convert.ToString(coetType[Convert.ToString(token[i])]);
                            else
                                tmps = Convert.ToString(token[i]);
                            prop.SetValue(line, tmps);
                            break;
                        case "System.Decimal":
                            decimal tmp = Convert.ToDecimal(token[i]);
                            prop.SetValue(line, tmp);
                            break;
                        case "System.DateTime":
                            DateTime dateID = DateTime.ParseExact(token[i].ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                            prop.SetValue(line, dateID);
                            break;
                    }
                    i++;
                }
                mHdrs.Add(line);
                i = 0;
            }
            return mHdrs;
        }