public static FixedWidthHelper ReadLines(List <string> lines)
            {
                var fw = new FixedWidthHelper();

                lines.ForEach(fw.AddDelimitedLine);
                return(fw);
            }
        private static void Main(string[] args)
        {
            var inputs = new List <string>
            {
                "FirstName,LastName,Title,BirthDate,HireDate,City,Region",
                "Nancy,Davolio,Sales Representative,1948-12-08,1992-05-01,Seattle,WA",
                "Andrew,Fuller,Vice PresidentSales,1952-02-19,1992-08-14,Tacoma,WA",
                "Janet,Leverling,Sales Representative,1963-08-30,1992-04-01,Kirkland,WA",
                "Margaret,Peacock,Sales Representative,1937-09-19,1993-05-03,Redmond,WA",
                "Steven,Buchanan,Sales Manager,1955-03-04,1993-10-17,London,NULL",
                "Michael,Suyama,Sales Representative,1963-07-02,1993-10-17,London,NULL",
                "Robert,King,Sales Representative,1960-05-29,1994-01-02,London,NULL",
                "Laura,Callahan,Inside Sales Coordinator,1958-01-09,1994-03-05,Seattle,WA",
                "Anne,Dodsworth,Sales Representative,1966-01-27,1994-11-15,London,NULL"
            };

            Console.Write(FixedWidthHelper.ReadLines(inputs)
                          .ToFixedLengthString());
            Console.ReadLine();
        }
Example #3
0
        protected abstract object GetValue(); // We do this instead of a virtual or abstract property because I want strong typing for the Value properties on the child classes

        /// <summary>
        /// Returns the value represented by this instance as a string formatted for inclusion in a fixed-width file.
        /// Any overrides for this method may include custom logic to pad the field as necessary.
        /// </summary>
        /// <returns></returns>
        public string GetStringForFile()
        {
            return(FixedWidthHelper.JustifyString((GetValue() ?? "").ToString(), Length, PaddingChar, JustifyType));
        }