public DirectVsDynamicTester() { var directMapper = SeparatedValueTypeMapper.Define <Person>(() => new Person()); directMapper.Property(x => x.Name).ColumnName("Name"); directMapper.Property(x => x.IQ).ColumnName("IQ"); directMapper.Property(x => x.BirthDate).ColumnName("BirthDate"); directMapper.Property(x => x.TopSpeed).ColumnName("TopSpeed"); directMapper.Property(x => x.IsActive).ColumnName("IsActive"); this.directMapper = directMapper; var dynamicMapper = SeparatedValueTypeMapper.DefineDynamic(typeof(Person)); dynamicMapper.StringProperty("Name").ColumnName("Name"); dynamicMapper.Int32Property("IQ").ColumnName("IQ"); dynamicMapper.DateTimeProperty("BirthDate").ColumnName("BirthDate"); dynamicMapper.DecimalProperty("TopSpeed").ColumnName("TopSpeed"); dynamicMapper.BooleanProperty("IsActive").ColumnName("IsActive"); this.dynamicMapper = dynamicMapper; this.people = Enumerable.Range(0, 10000).Select(i => new Person() { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m }).ToArray(); }
public void TestIgnoredMapping_HandlePreAndPostProcessing() { ISeparatedValueTypeMapper <IgnoredOnly> mapper = SeparatedValueTypeMapper.Define(() => new IgnoredOnly()); mapper.Ignored() .ColumnName("Ignored") .NullFormatter(NullFormatter.ForValue("NULL")) .OnParsing((ctx, value) => { Assert.AreEqual("NULL", value); return(value); }) .OnParsed((ctx, value) => { Assert.IsNull(value); return(value); }) .OnFormatting((ctx, value) => { Assert.IsNull(value); return(value); }) .OnFormatted((ctx, value) => { Assert.AreEqual("NULL", value); return(value); }); var ignored = mapper.GetSchema().ColumnDefinitions["Ignored"]; object value = ignored.Parse(null, "NULL"); Assert.IsNull(value); string formatted = ignored.Format(null, value); Assert.AreEqual("NULL", formatted); }
public SeparatedValueComplexPropertyMapping(ISeparatedValueTypeMapper <TEntity> mapper, IMemberAccessor member, int fileIndex, int workIndex) { this.mapper = mapper; this.Member = member; this.columnName = member.Name; this.FileIndex = fileIndex; this.WorkIndex = workIndex; }
public SeparatedValueComplexPropertyMapping( ISeparatedValueTypeMapper <TEntity> mapper, IMemberAccessor member, int physicalIndex, int logicalIndex) { this.mapper = mapper; Member = member; columnName = member.Name; PhysicalIndex = physicalIndex; LogicalIndex = logicalIndex; }
private static WeirdThing roundTrip(ISeparatedValueTypeMapper <WeirdThing> mapper, WeirdThing thing) { using (StringWriter writer = new StringWriter()) { mapper.Write(writer, new WeirdThing[] { thing }); var output = writer.ToString(); using (StringReader reader = new StringReader(output)) { var things = mapper.Read(reader).ToArray(); Assert.Equal(1, things.Count()); var deserialized = things.Single(); return(deserialized); } } }
public EmitVsReflectionWriteTester() { var mapper = SeparatedValueTypeMapper.Define <Person>(() => new Person()); mapper.Property(x => x.Name).ColumnName("Name"); mapper.Property(x => x.IQ).ColumnName("IQ"); mapper.Property(x => x.BirthDate).ColumnName("BirthDate"); mapper.Property(x => x.TopSpeed).ColumnName("TopSpeed"); this.mapper = mapper; this.people = Enumerable.Range(0, 10000).Select(i => new Person() { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m }).ToArray(); }
public SeparatedValueResult(ISeparatedValueTypeMapper <T> mapper, IEnumerable <T> data, SeparatedValueOptions options = null, string fileName = null, string contentType = null) { if (mapper == null) { throw new ArgumentNullException("mapper"); } if (data == null) { throw new ArgumentNullException("data"); } if (String.IsNullOrWhiteSpace(fileName)) { fileName = "file.txt"; } if (contentType == null) { contentType = "text/plain"; } this.writer = mapper.ToWriter(data); this.options = options; this.fileName = fileName; this.contentType = contentType; }
/// <summary> /// Provides the schema to use by default when no other matches are found. /// </summary> /// <param name="typeMapper">The default type mapper to use.</param> public void WithDefault <TEntity>(ISeparatedValueTypeMapper <TEntity> typeMapper) { WithDefault((IDynamicSeparatedValueTypeMapper)typeMapper); }
public SeparatedValueComplexPropertyMapping(ISeparatedValueTypeMapper <TEntity> mapper, PropertyInfo property) { this.mapper = mapper; this.property = property; this.columnName = property.Name; }
public void Use <TEntity>(ISeparatedValueTypeMapper <TEntity> typeMapper) { var dynamicMapper = (IDynamicSeparatedValueTypeMapper)typeMapper; Use(dynamicMapper); }
/// <summary> /// Provides the schema to use by default when no other matches are found. /// </summary> /// <param name="typeMapper">The default type mapper to use.</param> public void WithDefault <TEntity>(ISeparatedValueTypeMapper <TEntity> typeMapper) { this.defaultMapper = (IDynamicSeparatedValueTypeMapper)typeMapper; }