当前位置: 首页>>代码示例>>C#>>正文


C# MappingSchema.GetConverter方法代码示例

本文整理汇总了C#中MappingSchema.GetConverter方法的典型用法代码示例。如果您正苦于以下问题:C# MappingSchema.GetConverter方法的具体用法?C# MappingSchema.GetConverter怎么用?C# MappingSchema.GetConverter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MappingSchema的用法示例。


在下文中一共展示了MappingSchema.GetConverter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DefaultValue1

		public void DefaultValue1()
		{
			var ms = new MappingSchema();

			ms.SetDefaultValue(typeof(int), -1);

			var c = ms.GetConverter<int?,int>();

			Assert.AreEqual(-1, c(null));
		}
开发者ID:jkshan,项目名称:linq2db,代码行数:10,代码来源:MappingSchemaTest.cs

示例2: BaseSchema1

		public void BaseSchema1()
		{
			var ms1 = new MappingSchema();
			var ms2 = new MappingSchema(ms1);

			ms1.SetDefaultValue(typeof(int), -1);
			ms2.SetDefaultValue(typeof(int), -2);

			var c1 = ms1.GetConverter<int?,int>();
			var c2 = ms2.GetConverter<int?,int>();

			Assert.AreEqual(-1, c1(null));
			Assert.AreEqual(-2, c2(null));
		}
开发者ID:jkshan,项目名称:linq2db,代码行数:14,代码来源:MappingSchemaTest.cs

示例3: DefaultValue3

		public void DefaultValue3()
		{
			var ms1 = new MappingSchema();
			var ms2 = new MappingSchema(ms1);

			ms1.SetConvertExpression<int?,int>(i => i.Value * 2);
			ms2.SetDefaultValue(typeof(int), -1);

			var c1 = ms1.GetConverter<int?,int>();
			var c2 = ms2.GetConverter<int?,int>();

			Assert.AreEqual( 4, c1(2));
			Assert.AreEqual( 0, c1(null));
			Assert.AreEqual( 4, c2(2));
			Assert.AreEqual(-1, c2(null));
		}
开发者ID:jkshan,项目名称:linq2db,代码行数:16,代码来源:MappingSchemaTest.cs

示例4: BaseSchema2

		public void BaseSchema2()
		{
			var ms1 = new MappingSchema();
			var ms2 = new MappingSchema(ms1);

			Convert<DateTime,string>.Lambda = d => d.ToString(DateTimeFormatInfo.InvariantInfo);

			ms1.SetConverter<DateTime,string>(d => d.ToString(new CultureInfo("en-US", false).DateTimeFormat));
			ms2.SetConverter<DateTime,string>(d => d.ToString(new CultureInfo("ru-RU", false).DateTimeFormat));

			{
				var c0 = Convert<DateTime,string>.Lambda;
				var c1 = ms1.GetConverter<DateTime,string>();
				var c2 = ms2.GetConverter<DateTime,string>();

				Assert.AreEqual("01/20/2012 16:30:40",  c0(new DateTime(2012, 1, 20, 16, 30, 40, 50, DateTimeKind.Utc)));
				Assert.AreEqual("1/20/2012 4:30:40 PM", c1(new DateTime(2012, 1, 20, 16, 30, 40, 50, DateTimeKind.Utc)));
				Assert.AreEqual("20.01.2012 16:30:40",  c2(new DateTime(2012, 1, 20, 16, 30, 40, 50, DateTimeKind.Utc)));
			}

			Convert<string,DateTime>.Expression = s => DateTime.Parse(s, DateTimeFormatInfo.InvariantInfo);

			ms1.SetConvertExpression<string,DateTime>(s => DateTime.Parse(s, new CultureInfo("en-US", false).DateTimeFormat));
			ms2.SetConvertExpression<string,DateTime>(s => DateTime.Parse(s, new CultureInfo("ru-RU", false).DateTimeFormat));

			{
				var c0 = Convert<string,DateTime>.Lambda;
				var c1 = ms1.GetConverter<string,DateTime>();
				var c2 = ms2.GetConverter<string,DateTime>();

				Assert.AreEqual(new DateTime(2012, 1, 20, 16, 30, 40), c0("01/20/2012 16:30:40"));
				Assert.AreEqual(new DateTime(2012, 1, 20, 16, 30, 40), c1("1/20/2012 4:30:40 PM"));
				Assert.AreEqual(new DateTime(2012, 1, 20, 16, 30, 40), c2("20.01.2012 16:30:40"));
			}
		}
开发者ID:jkshan,项目名称:linq2db,代码行数:35,代码来源:MappingSchemaTest.cs

示例5: CultureInfo

		public void CultureInfo()
		{
			var ms = new MappingSchema();

			ms.SetCultureInfo(new CultureInfo("ru-RU", false));

			Assert.AreEqual("20.01.2012 16:30:40",                 ms.GetConverter<DateTime,string>()(new DateTime(2012, 1, 20, 16, 30, 40)));
			Assert.AreEqual(new DateTime(2012, 1, 20, 16, 30, 40), ms.GetConverter<string,DateTime>()("20.01.2012 16:30:40"));
			Assert.AreEqual("100000,999",                          ms.GetConverter<decimal,string> ()(100000.999m));
			Assert.AreEqual(100000.999m,                           ms.GetConverter<string,decimal> ()("100000,999"));
			Assert.AreEqual(100000.999m,                           ConvertTo<decimal>.From("100000.999"));
			Assert.AreEqual("100000,999",                          ms.GetConverter<double,string>  ()(100000.999));
			Assert.AreEqual(100000.999,                            ms.GetConverter<string,double>  ()("100000,999"));
		}
开发者ID:jkshan,项目名称:linq2db,代码行数:14,代码来源:MappingSchemaTest.cs

示例6: CultureInfo

		public void CultureInfo()
		{
			var ms = new MappingSchema();

#if !NETSTANDARD
			ms.SetCultureInfo(new CultureInfo("ru-RU", false));
#else
			ms.SetCultureInfo(new CultureInfo("ru-RU"));
#endif 

			Assert.AreEqual("20.01.2012 16:30:40",                 ms.GetConverter<DateTime,string>()(new DateTime(2012, 1, 20, 16, 30, 40)));
			Assert.AreEqual(new DateTime(2012, 1, 20, 16, 30, 40), ms.GetConverter<string,DateTime>()("20.01.2012 16:30:40"));
			Assert.AreEqual("100000,999",                          ms.GetConverter<decimal,string> ()(100000.999m));
			Assert.AreEqual(100000.999m,                           ms.GetConverter<string,decimal> ()("100000,999"));
			//Assert.AreEqual(100000.999m,                           ConvertTo<decimal>.From("100000.999")); this will fail if System Locale is ru-RU
			Assert.AreEqual("100000,999",                          ms.GetConverter<double,string>  ()(100000.999));
			Assert.AreEqual(100000.999,                            ms.GetConverter<string,double>  ()("100000,999"));
		}
开发者ID:ronnyek,项目名称:linq2db,代码行数:18,代码来源:MappingSchemaTests.cs


注:本文中的MappingSchema.GetConverter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。