public void AutoConvertInterfaceTest() { Guid guid = Guid.NewGuid(); AutoSource source = new AutoSource(1, "as", null, guid, 2); Target target = new Target(); Assert.That(target.Prop1, Is.EqualTo(default(int))); Assert.That(target.Prop2, Is.EqualTo(default(string))); Assert.That(target.Prop3, Is.EqualTo(default(object))); Assert.That(target.Prop4, Is.EqualTo(default(Guid))); Assert.That(target.Prop5, Is.EqualTo(default(int))); SimpleConverter simpleConverter = new SimpleConverter(); simpleConverter.Map(source, target); Assert.That(target.Prop1, Is.EqualTo(source.Prop1)); Assert.That(target.Prop2, Is.EqualTo(source.Prop2)); Assert.That(target.Prop3, Is.EqualTo(source.Prop3)); Assert.That(target.Prop4, Is.EqualTo(source.Prop4)); Assert.That(target.Prop5, Is.EqualTo(source.Prop5)); }
public static void Main(string[] args) { AutoSource source = new AutoSource(1, "1", new object(), Guid.NewGuid(), 1); Target target = new Target(); SimpleConverter simpleconverter = new SimpleConverter(); Stopwatch stopwatchSimple = TakeTime(IterateOverTests(() => simpleconverter.Map(source, target))); var map = ManualMap<AutoSource, Target>.New .AddMap(a => a.Prop1, b => b.Prop1) .AddMap(a => a.Prop2, b => b.Prop2) .AddMap(a => a.Prop3, b => b.Prop3) .AddMap(a => a.Prop4, b => b.Prop4) .AddMap(a => a.Prop5, b => b.Prop5); Stopwatch stopwatchManual = TakeTime(IterateOverTests(() => map.Map(source, target))); Stopwatch stopwatchAuto = TakeTime(IterateOverTests(() => AutoConverter.AutoConvert(source, target))); LinqMapSource source2 = new LinqMapSource(1, 2, 3, 4, 5); LinqMapTarget target2 = new LinqMapTarget(); var linqMap = LinqMap<LinqMapSource, LinqMapTarget>.New .AddMap(a => a.Source1, (a, b) => a.Target1 = b) .AddMap(a => a.Source2, (a, b) => a.Target2 = b) .AddMap(a => a.Source3, (a, b) => a.Target3 = b) .AddMap(a => a.Source4, (a, b) => a.Target4 = b) .AddMap(a => a.Source5, (a, b) => a.Target5 = b); Stopwatch stopwatchLinq = TakeTime(IterateOverTests(() => linqMap.Map(source2, target2))); Console.WriteLine(stopwatchSimple.ElapsedMilliseconds); Console.WriteLine(stopwatchManual.ElapsedMilliseconds); Console.WriteLine(stopwatchAuto.ElapsedMilliseconds); Console.WriteLine(stopwatchLinq.ElapsedMilliseconds); Console.Read(); }
public IXmlListElementConfiguration WithConverter(SimpleConverter <string> converter) { _converter = converter; return(this); }
IXmlListAttributeConfiguration IWithMember <IXmlListAttributeConfiguration> .WithConverter( SimpleConverter <string> converter) { WithConverter(converter); return(this); }
public IIniKeySerializerConfiguration WithConverter(SimpleConverter<string> converter) { _converter = converter; return this; }
public HeaderedFileListKeyMapper(string?membername, Type targetType, string?keyName, SimpleConverter <string>?converter) : base(membername, targetType) { _keyName = keyName; _converter = converter; if (TargetMember == null) { return; } _listBuilder = new ListBuilder(MemberType); var elementType = _listBuilder.ElemenType; if (_converter == null && elementType != null) { _converter = ConverterFactory.CreateConverter(TargetMember, elementType); } }
public IIniKeySerializerConfiguration WithConverter(SimpleConverter <string> converter) { _converter = converter; return(this); }
public KoobooSimpleConverter() { converter = new SimpleConverter <T>(); }
public IHeaderedFileKeywordConfiguration WithConverter(SimpleConverter<string> converter) { _converter = converter; return this; }
public IXmlAttributConfiguration WithConverter(SimpleConverter<string> converter) { _converter = converter; return this; }
public void CanConvertFromRealNumberString <T>(T expected, string value, Type type) { var actual = (T)SimpleConverter <T> .ConvertFrom(CultureInfo.InvariantCulture, value, type); Assert.Equal(expected, actual); }
public void WordConvertTest() { var dataSource = new DataSource { { "QuotationNo", new DataItem { Type = (int)RenderMode.Plain, Value = "QR140507000" } }, }; var item = new DataItem { Type = (int)RenderMode.Plain, Value = "2014-05-07" }; dataSource.Add("Date", item); item = new DataItem { Type = (int)RenderMode.Plain, Value = "7623" }; dataSource.Add("CustomerCode", item); item = new DataItem { Type = (int)RenderMode.Plain, Value = string.Empty }; dataSource.Add("VenderCode", item); item = new DataItem { Type = (int)RenderMode.Plain, Value = "Microsoft Corporation" }; dataSource.Add("CustomerName", item); item = new DataItem { Type = (int)RenderMode.Plain, Value = "Jon Aswad" }; dataSource.Add("To", item); item = new DataItem { Type = (int)RenderMode.Plain, Value = "张振龙[Zhenlong Zhang]" }; dataSource.Add("From", item); item = new DataItem { Type = (int)RenderMode.Plain, Value = "One Microsoft Way,ASHBURN,VA,20147" }; dataSource.Add("ToAddress", item); dataSource.Add("FromAddress", DataItem.NewItem(RenderMode.Plain, "No.98-5, Rd.19 Hangzhou Eco.& Tec. Dev. Zone Hangzhou")); dataSource.Add("ToTel", DataItem.NewItem(RenderMode.Plain, "+1(802)8647358 ")); dataSource.Add("FromTel", DataItem.NewItem(RenderMode.Plain, "+86-571-86714425-323")); dataSource.Add("ToFax", DataItem.NewItem(RenderMode.Plain, "")); dataSource.Add("FromFax", DataItem.NewItem(RenderMode.Plain, "+86-571-86714426-229")); var data = new DataTable(); var column = new DataColumn("No_0") { DataType = typeof(int) }; data.Columns.Add(column); column = new DataColumn("Item_0") { DataType = typeof(string) }; data.Columns.Add(column); column = new DataColumn("Desc_0") { DataType = typeof(string) }; data.Columns.Add(column); column = new DataColumn("Qty_0") { DataType = typeof(double) }; data.Columns.Add(column); column = new DataColumn("UP_0") { DataType = typeof(double) }; data.Columns.Add(column); column = new DataColumn("CUR_0") { DataType = typeof(string) }; data.Columns.Add(column); column = new DataColumn("AMT_0") { DataType = typeof(double) }; data.Columns.Add(column); var random = new Random(); double sum = 0.0; for (int i = 0; i < 32; i++) { double value = random.NextDouble(); DataRow row = data.NewRow(); row["No_0"] = i + 1; row["Item_0"] = string.Format("APEA30{0}", i + 1); row["Desc_0"] = string.Format("SHIELD-EMI,FENCE,FRONTSIDE,1{0}", i + 1); row["Qty_0"] = 1.0000; row["UP_0"] = value; row["CUR_0"] = "USD"; row["AMT_0"] = value; sum += value; data.Rows.Add(row); } dataSource.Add("Quotation", DataItem.NewItem(RenderMode.List, data)); dataSource.Add("Remark", DataItem.NewItem(RenderMode.Plain, @"* This quotation is set up based on current design on May-7-2014. * This quotation is flexible according to the change of design in the future. * Exchange rate: 1 USD = 6.2 RMB. This quotation will be updated if currency fluctuates more than 2%.")); dataSource.Add("PriceTerm", DataItem.NewItem(RenderMode.Plain, "DAP Suzhou")); dataSource.Add("Payment", DataItem.NewItem(RenderMode.Plain, "T/T 30 days")); dataSource.Add("LeadTime", DataItem.NewItem(RenderMode.Plain, "")); dataSource.Add("Amt_Sum", DataItem.NewItem(RenderMode.Plain, sum.ToString(CultureInfo.InvariantCulture))); dataSource.Add("Cur_Sum", DataItem.NewItem(RenderMode.Plain, "USD")); dataSource.Add("Origin", DataItem.NewItem(RenderMode.Plain, "P.R.Chinas")); dataSource.Add("Packing", DataItem.NewItem(RenderMode.Plain, "Standard bulk packing")); dataSource.Add("Beneficiary", DataItem.NewItem(RenderMode.Plain, "Hangzhou Amphenol Phoenix Telecom Parts Co., Ltd.")); dataSource.Add("AccountNo", DataItem.NewItem(RenderMode.Plain, "3753 5834 2400")); dataSource.Add("Name", DataItem.NewItem(RenderMode.Plain, "Bank Of China Hangzhou Economical & Technological Development Area Sub-Branch")); dataSource.Add("BankAddress", DataItem.NewItem(RenderMode.Plain, "NO 3 Road Hangzhou Economic And Technological Development Zone Hangzhou China")); dataSource.Add("SwiftCode", DataItem.NewItem(RenderMode.Plain, "BKCHCNBJ910")); dataSource.Add("PM", DataItem.NewItem(RenderMode.Image, "D:\\Template\\zhenglong.zhang.png")); var serializer = new JsonSerializer(); serializer.Converters.Add(new DataSourceJsonConverter()); serializer.Converters.Add(new DataItemJsonConverter()); JObject obj = JObject.FromObject(dataSource, serializer); string s = obj.ToString(); var doc = new DocumentEntity { ID = Guid.NewGuid(), TemplateName = "模板.docx", OutputType = (int)(OutputType.PDF | OutputType.Word), DataSource = s }; // 测试文档转换 var converter = new SimpleConverter(); converter.Convert(doc); // 再生产环境可以调用如下语句直接加入数据库,然后增加文档转换服务自定转换 //DocumentService.Instance.AddDocument(doc); //Enterprises.Framework.Plugin.Office.Converters.DocumentConvert service = new Enterprises.Framework.Plugin.Office.Converters.DocumentConvert(); //service.Process(); }
public XmlElementSerializer([NotNull] XmlElementTarget target, [NotNull] SimpleConverter<string> converter) { _target = target; _converter = converter; }
public XmlListMapper(string?membername, Type targetType, XmlElementTarget rootTarget, XmlElementTarget target, SimpleConverter <string>?converter) : base(membername, targetType) { _rootTarget = rootTarget; if (MemberType != null) { _listBuilder = new ListBuilder(MemberType); } if (converter == null && _listBuilder != null) { converter = ConverterFactory.CreateConverter(TargetMember, _listBuilder.ElemenType); } _serializer = new XmlElementSerializer(target, converter); }
public IIniKeySerializerConfiguration WithConverter(SimpleConverter<IEnumerable<string>> converter) { _listConverter = converter; return this; }
static TypeDescriptor() { SimpleConverter.Register(); }
public IXmlAttributConfiguration WithConverter(SimpleConverter <string> converter) { _converter = converter; return(this); }
public ApplicationBinding(string path) : base(path) { Converter = new SimpleConverter <object, object>(i => i ?? Nothing.Do, i => i); Source = Get.Where <Configuration.BaseApplication>(); UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; }
public KoobooSimpleConverter(Dictionary <string, int> Columns) { converter = new SimpleConverter <T>(Columns); }
public IHeaderedFileKeywordConfiguration WithConverter(SimpleConverter <string> converter) { _converter = converter; return(this); }
public IIniKeySerializerConfiguration WithConverter(SimpleConverter <IEnumerable <string> >?converter) { _listConverter = converter; return(this); }
public void AutoConvertUnableToConvertTest() { Guid guid = Guid.NewGuid(); AutoSourceTooSmall source = new AutoSourceTooSmall(1, "as", null, guid); Target target = new Target(); SimpleConverter simpleConverter = new SimpleConverter(); simpleConverter.Map(source, target); }
public XmlElementSerializer(XmlElementTarget?target, SimpleConverter <string>?converter) { _target = target; _converter = converter; }
public UniversalListConverter([NotNull] SimpleConverter <string> baseConverter, [NotNull] ListBuilder listBuilder) { _baseConverter = Argument.NotNull(baseConverter, nameof(baseConverter)); _listBuilder = Argument.NotNull(listBuilder, nameof(listBuilder)); }