• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# TypeConversion.TypeConverterOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CsvHelper.TypeConversion.TypeConverterOptions的典型用法代码示例。如果您正苦于以下问题:C# TypeConverterOptions类的具体用法?C# TypeConverterOptions怎么用?C# TypeConverterOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeConverterOptions类属于CsvHelper.TypeConversion命名空间,在下文中一共展示了TypeConverterOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ConvertTo

 protected override string ConvertTo(TypeConverterOptions options, object value)
 {
     double d = Convert.ToDouble(value);
     string format = options.NumberStyle.HasValue ? "#.#" : "###.#";
     string s = d.IsZero() ? "Unknown" : d.ToString(format);
     return s;
 }
开发者ID:tyhuber,项目名称:QueryWatchedMovies,代码行数:7,代码来源:DoubleConverter.cs


示例2: ConvertTo

 protected override string ConvertTo(TypeConverterOptions options, object value)
 {
     if (value == null) return "Unknown";
     var dt = Convert.ToDateTime(value);
     if (dt == DateTime.MinValue) return "Unknown";
     return dt.ToString("g");
 }
开发者ID:tyhuber,项目名称:QueryWatchedMovies,代码行数:7,代码来源:DateConverter.cs


示例3: ConvertToString

        public string ConvertToString(TypeConverterOptions options, object value)
        {
            var color = (Color)value;
            var stringValue = ColorTranslator.ToHtml(color);

            return stringValue;
        }
开发者ID:jrolstad,项目名称:traverse,代码行数:7,代码来源:HexadecimalColorConverter.cs


示例4: ConvertFromStringTest

		public void ConvertFromStringTest()
		{
			var converter = new EnumConverter( typeof( TestEnum ) );
			var typeConverterOptions = new TypeConverterOptions
			{
				CultureInfo = CultureInfo.CurrentCulture
			};

			Assert.AreEqual( TestEnum.One, converter.ConvertFromString( typeConverterOptions, "One" ) );
			Assert.AreEqual( TestEnum.One, converter.ConvertFromString( typeConverterOptions, "one" ) );
			Assert.AreEqual( TestEnum.One, converter.ConvertFromString( typeConverterOptions, "1" ) );
			try
			{
				Assert.AreEqual( TestEnum.One, converter.ConvertFromString( typeConverterOptions, "" ) );
				Assert.Fail();
			}
			catch( CsvTypeConverterException )
			{
			}

			try
			{
				Assert.AreEqual( TestEnum.One, converter.ConvertFromString( typeConverterOptions, null ) );
				Assert.Fail();
			}
			catch( CsvTypeConverterException )
			{
			}
		}
开发者ID:jhamm,项目名称:CsvHelper,代码行数:29,代码来源:EnumConverterTests.cs


示例5: ConvertFromString

		/// <summary>
		/// Converts the string to an object.
		/// </summary>
		/// <param name="options">The options to use when converting.</param>
		/// <param name="text">The string to convert to an object.</param>
		/// <returns>The object created from the string.</returns>
		public override object ConvertFromString( TypeConverterOptions options, string text )
		{
			var formatProvider = (IFormatProvider)options.CultureInfo;

			TimeSpan span;

#if !NET_2_0 && !NET_3_5 && !PCL
			var timeSpanStyle = options.TimeSpanStyle ?? TimeSpanStyles.None;
			if( !string.IsNullOrEmpty( options.Format ) && TimeSpan.TryParseExact( text, options.Format, formatProvider, timeSpanStyle, out span ) )
			{
				return span;
			}

			if( string.IsNullOrEmpty( options.Format ) && TimeSpan.TryParse( text, formatProvider, out span ) )
			{
				return span;
			}
#else
			if( TimeSpan.TryParse( text, out span ) )
			{
				return span;
			}
#endif

			return base.ConvertFromString( options, text );
		}
开发者ID:adbre,项目名称:CsvHelper,代码行数:32,代码来源:TimeSpanConverter.cs


示例6: ConvertTest

        public void ConvertTest()
        {
            var converter = new EnumerableConverter();
            var typeConverterOptions = new TypeConverterOptions
            {
                CultureInfo = CultureInfo.CurrentCulture
            };

            Assert.IsTrue( converter.CanConvertFrom( typeof( string ) ) );
            Assert.IsTrue( converter.CanConvertTo( typeof( string ) ) );
            try
            {
                converter.ConvertFromString( typeConverterOptions, "" );
                Assert.Fail();
            }
            catch( CsvTypeConverterException )
            {
            }
            try
            {
                converter.ConvertToString( typeConverterOptions, 5 );
                Assert.Fail();
            }
            catch( CsvTypeConverterException )
            {
            }
        }
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:27,代码来源:EnumerableConverterTests.cs


示例7: ConvertFromStringTest

        public void ConvertFromStringTest()
        {
            var converter = new DateTimeConverter();
            var typeConverterOptions = new TypeConverterOptions
            {
                CultureInfo = CultureInfo.CurrentCulture
            };

            var dateTime = DateTime.Now;

            // Valid conversions.
            Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( typeConverterOptions, dateTime.ToString() ).ToString() );
            Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( typeConverterOptions, dateTime.ToString( "o" ) ).ToString() );
            Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( typeConverterOptions, " " + dateTime + " " ).ToString() );

            // Invalid conversions.
            try
            {
                converter.ConvertFromString( typeConverterOptions, null );
                Assert.Fail();
            }
            catch( CsvTypeConverterException )
            {
            }
        }
开发者ID:phaufe,项目名称:CsvHelper,代码行数:25,代码来源:DateTimeConverterTests.cs


示例8: Merge

		/// <summary>
		/// Merges TypeConverterOptions by applying the values of sources in order to a
		/// new TypeConverterOptions instance.
		/// </summary>
		/// <param name="sources">The sources that will be applied.</param>
		/// <returns>A new instance of TypeConverterOptions with the source applied to it.</returns>
		public static TypeConverterOptions Merge( params TypeConverterOptions[] sources )
		{
			var options = new TypeConverterOptions();
			foreach( var source in sources )
			{
				if( source == null )
				{
					continue;
				}

				if( source.CultureInfo != null )
				{
					options.CultureInfo = source.CultureInfo;
				}

				if( source.DateTimeStyle != null )
				{
					options.DateTimeStyle = source.DateTimeStyle;
				}

#if !NET_2_0 && !NET_3_5 && !PCL
				if( source.TimeSpanStyle != null )
				{
					options.TimeSpanStyle = source.TimeSpanStyle;
				}
#endif

				if( source.NumberStyle != null )
				{
					options.NumberStyle = source.NumberStyle;
				}

				if( source.Format != null )
				{
					options.Format = source.Format;
				}

#if NET_2_0
				if( !EnumerableHelper.SequenceEqual( options.booleanTrueValues, source.booleanTrueValues ) )
#else
				if( !options.booleanTrueValues.SequenceEqual( source.booleanTrueValues ) )
#endif
				{
					options.booleanTrueValues.Clear();
					options.booleanTrueValues.AddRange( source.booleanTrueValues );
				}

#if NET_2_0
				if( !EnumerableHelper.SequenceEqual( options.booleanFalseValues, source.booleanFalseValues ) )
#else
				if( !options.booleanFalseValues.SequenceEqual( source.booleanFalseValues ) )
#endif
				{
					options.booleanFalseValues.Clear();
					options.booleanFalseValues.AddRange( source.booleanFalseValues );
				}
			}

			return options;
		}
开发者ID:koskedk,项目名称:CsvHelper,代码行数:66,代码来源:TypeConverterOptions.cs


示例9: ConvertFromString

 /// <summary>
 ///     Converts the string to an object.
 /// </summary>
 /// <param name="options">The options to use when converting.</param>
 /// <param name="text">The string to convert to an object.</param>
 /// <returns>
 ///     The object created from the string.
 /// </returns>
 public override object ConvertFromString(TypeConverterOptions options, string text)
 {
     var numberStyle = options.NumberStyle;
     var style = numberStyle.HasValue ? numberStyle.GetValueOrDefault() : NumberStyles.Float;
     double result;
     if (double.TryParse(text, style, options.CultureInfo, out result))
         return Length.FromMillimeters(result);
     return base.ConvertFromString(options, text);
 }
开发者ID:oysteinkrog,项目名称:thing_libutils,代码行数:17,代码来源:LengthMillimeterConverter.cs


示例10: ConvertFromString

        public object ConvertFromString(TypeConverterOptions options, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
                return new DateTime?();

            var value = ParseDate(options, text);

            return value;
        }
开发者ID:jrolstad,项目名称:traverse,代码行数:9,代码来源:YyyymmddDateConverter.cs


示例11: ConvertFromString

        public override object ConvertFromString(TypeConverterOptions options, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return null;
            }

            return base.ConvertFromString(options, text);
        }
开发者ID:gipasoft,项目名称:Sfera,代码行数:9,代码来源:DateTimeNullableConverter.cs


示例12: ConvertFromString

		/// <summary>
		/// Converts the string to an object.
		/// </summary>
		/// <param name="options">The options to use when converting.</param>
		/// <param name="text">The string to convert to an object.</param>
		/// <returns>The object created from the string.</returns>
		public override object ConvertFromString( TypeConverterOptions options, string text )
		{
			if( string.IsNullOrEmpty( text ) )
			{
				return null;
			}

			return UnderlyingTypeConverter.ConvertFromString( options, text );
		}
开发者ID:koskedk,项目名称:CsvHelper,代码行数:15,代码来源:NullableConverter.cs


示例13: ConvertFromString

        public object ConvertFromString(TypeConverterOptions options, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                text = Resources.DependencyNone;
            }

            return text;
        }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:9,代码来源:DependencyConverter.cs


示例14: ConvertFromString

        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="options">The options to use when converting.</param>
        /// <param name="text">The string to convert to an object.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( TypeConverterOptions options, string text )
        {
            if( text == null )
            {
                return base.ConvertFromString( options, text );
            }

            return new Guid( text );
        }
开发者ID:punker76,项目名称:CsvHelper,代码行数:15,代码来源:GuidConverter.cs


示例15: ConvertFromString

        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="options">The options to use when converting.</param>
        /// <param name="text">The string to convert to an object.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( TypeConverterOptions options, string text )
        {
            if( text == null )
            {
                return string.Empty;
            }

            return text;
        }
开发者ID:foxor,项目名称:MorphiumCard,代码行数:15,代码来源:StringConverter.cs


示例16: ConvertToString

        public string ConvertToString(TypeConverterOptions options, object value)
        {
            if (value == null)
                return null;

            var dateValue = (DateTime) value;
            var formattedDate = dateValue.ToString("yyyyMMdd");

            return formattedDate;
        }
开发者ID:jrolstad,项目名称:traverse,代码行数:10,代码来源:YyyymmddDateConverter.cs


示例17: ConvertFromString

        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="options">The options to use when converting.</param>
        /// <param name="text">The string to convert to an object.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( TypeConverterOptions options, string text )
        {
            TimeSpan span;

            if( TimeSpan.TryParse( text, out span ) )
            {
                return span;
            }

            return base.ConvertFromString( options, text );
        }
开发者ID:foxor,项目名称:MorphiumCard,代码行数:17,代码来源:TimeSpanConverter.cs


示例18: ConvertFromString

 /// <summary>
 /// Converts the string to an object.
 /// </summary>
 /// <param name="options">The options to use when converting.</param>
 /// <param name="text">The string to convert to an object.</param>
 /// <returns>The object created from the string.</returns>
 public override object ConvertFromString( TypeConverterOptions options, string text )
 {
     try
     {
         return Enum.Parse( type, text + "some unneeded string here", true );
     }
     catch
     {
         return base.ConvertFromString( options, text );
     }
 }
开发者ID:AdrianDamyanov,项目名称:Altakiril,代码行数:17,代码来源:EnumConverter.cs


示例19: ConvertToStringTest

        public void ConvertToStringTest()
        {
            var converter = new ByteConverter();
            var typeConverterOptions = new TypeConverterOptions
            {
                CultureInfo = CultureInfo.CurrentCulture
            };

            Assert.AreEqual( "123", converter.ConvertToString( typeConverterOptions, (byte)123 ) );

            Assert.AreEqual( "", converter.ConvertToString( typeConverterOptions, null ) );
        }
开发者ID:btebaldi,项目名称:CsvHelper,代码行数:12,代码来源:ByteConverterTests.cs


示例20: ConvertFromString

		/// <summary>
		/// Converts the string to an object.
		/// </summary>
		/// <param name="options">The options to use when converting.</param>
		/// <param name="text">The string to convert to an object.</param>
		/// <returns>The object created from the string.</returns>
		public override object ConvertFromString( TypeConverterOptions options, string text )
		{
			var numberStyle = options.NumberStyle ?? NumberStyles.Float;

			float f;
			if( float.TryParse( text, numberStyle, options.CultureInfo, out f ) )
			{
				return f;
			}

			return base.ConvertFromString( options, text );
		}
开发者ID:adbre,项目名称:CsvHelper,代码行数:18,代码来源:SingleConverter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cubico.UnitConverter类代码示例发布时间:2022-05-24
下一篇:
C# Mocks.ParserMock类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap