コード例 #1
0
        static void ConfigFirstApproachReadAsTypedRecords()
        {
            ChoFixedLengthRecordConfiguration config = new ChoFixedLengthRecordConfiguration();

            config.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration("Id", 0, 8)
            {
                FieldType = typeof(int)
            });
            config.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration("Name", 8, 10)
            {
                FieldType = typeof(string)
            });

            EmployeeRecSimple row = null;

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                    using (var writer = new StreamWriter(stream))
                        using (var parser = new ChoFixedLengthReader <EmployeeRecSimple>(reader, config).WithFirstLineHeader())
                        {
                            writer.WriteLine("Id      Name      ");
                            writer.WriteLine("1       Carl      ");
                            writer.WriteLine("2       Mark      ");
                            writer.Flush();
                            stream.Position = 0;

                            while ((row = parser.Read()) != null)
                            {
                                Console.WriteLine(row.ToStringEx());
                            }
                        }
        }
コード例 #2
0
        static void DefaultValueUsedViaCodeFirstApproach()
        {
            EmployeeRecSimple row = null;

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                    using (var writer = new StreamWriter(stream))
                        using (var parser = new ChoFixedLengthReader <EmployeeRecSimple>(reader))
                        {
                            writer.WriteLine("001Carl 08/12/2016$100,000                      0F");
                            writer.WriteLine("002MarkS01/01/2010$500,000                      1C");
                            writer.Flush();
                            stream.Position = 0;

                            while ((row = parser.Read()) != null)
                            {
                                Console.WriteLine(row.ToStringEx());
                            }
                        }
        }
コード例 #3
0
        static void CodeFirstApproach()
        {
            EmployeeRecSimple row = null;

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                    using (var writer = new StreamWriter(stream))
                        using (var parser = new ChoFixedLengthReader <EmployeeRecSimple>(reader).WithFirstLineHeader())
                        {
                            writer.WriteLine("Id      Name      ");
                            writer.WriteLine("1       Carl      ");
                            writer.WriteLine("2       Mark      ");
                            writer.Flush();
                            stream.Position = 0;

                            while ((row = parser.Read()) != null)
                            {
                                Console.WriteLine(row.ToStringEx());
                            }
                        }
        }