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


C# TypeConverter.ToString方法代码示例

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


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

示例1: CheckConvert

		public void CheckConvert(int expect_from, int expect_to, TypeConverter conv, Type type) {
			int from_count	 = 0;
			int to_count	 = 0;

			foreach (Type t in typeof(int).Assembly.GetTypes ()) {
				if (conv.CanConvertFrom(null, t)) {
					from_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion from {1} supported", conv.ToString(), t.ToString());
					}
				}

				if (conv.CanConvertTo(null, t)) {
					to_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion to {1} supported", conv.ToString(), t.ToString());
					}
				}
			}

#if not
			foreach (Type t in type.Assembly.GetTypes ()) {
				if (conv.CanConvertFrom(null, t)) {
					from_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion from {1} supported", conv.ToString(), t.ToString());
					}
				}

				if (conv.CanConvertTo(null, t)) {
					to_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion to {1} supported", conv.ToString(), t.ToString());
					}
				}
			}
#endif

			if (from_count != expect_from) {
				if (verbose > 0) {
					Console.WriteLine("{0}: ConvertFrom expected {1}, returned {2}", conv.ToString(), expect_from, from_count);
				}
				failed++;
			}

			if (to_count != expect_to) {
				if (verbose > 0) {
					Console.WriteLine("{0}: ConvertTo expected {1}, returned {2}", conv.ToString(), expect_to, to_count);
				}
				failed++;
			}

		}
开发者ID:hitswa,项目名称:winforms,代码行数:53,代码来源:converters.cs

示例2: CheckConversion

		public void CheckConversion(object check, object expect, TypeConverter conv, Type type, bool test_from, bool test_to, CultureInfo culture) {
			object obj;
			object result;

			obj = check;

			if (debug > 0) {
				Console.WriteLine("{0}: CheckConversion, checking {1}({2}) <-> {3}({4})", conv.ToString(), check.GetType().ToString(), check.ToString(), type.ToString(), expect != null ? expect.ToString() : "null");
			}

			if (test_to) {
				obj = conv.ConvertTo(null, culture, check, type);

				if (obj == null) {
					if (expect != null) {
						failed++;
						Console.WriteLine("{0}: ConvertTo failed, type {1}, expected {2}, got null", conv.ToString(), type.ToString(), expect.ToString());
					}
					return;
				}

				// Intermediate verification
				if (expect != null && !obj.Equals(expect)) {
					failed++;
					if (verbose > 0) {
						Console.WriteLine("{0}: ConvertTo failed, type {1}, expected {2}, got {3}", conv.ToString(), type.ToString(), expect.ToString(), obj.ToString());
					}
				}

				if (debug > 1) {
					Console.WriteLine("{0}: CheckConversion, ConvertTo result: '{1}')", conv.ToString(), obj);
				}
			}


			if (test_from) {
				result = conv.ConvertFrom(null, culture, obj);

				if (test_to) {
					// Roundtrip check
					if (!check.Equals(result)) {
						failed++;
						if (verbose > 0) {
							Console.WriteLine("{0}: ConvertTo/ConvertFrom roundtrip failed, type {1}", conv.ToString(), type.ToString());
						}
					}

				} else {
					if (!expect.Equals(result)) {
						failed++;
						if (verbose > 0) {
							Console.WriteLine("{0}: ConvertFrom failed, type {1}", conv.ToString(), type.ToString());
						}
					}
				}

				if (debug > 1) {
					Console.WriteLine("{0}: CheckConversion, ConvertFrom result: '{1}')", conv.ToString(), result);
				}
			}
		}
开发者ID:hitswa,项目名称:winforms,代码行数:61,代码来源:converters.cs

示例3: CheckStandardValuesSupported

		public void CheckStandardValuesSupported(bool expect, TypeConverter conv) {
			bool result;

			result = conv.GetStandardValuesSupported(null);

			if (result != expect) {
				failed++;
				if (verbose > 0) {
					Console.WriteLine("{0}: GetStandardValuesSupported expected {1}, returned {2}", conv.ToString(), expect, result);
				}
			}
		}
开发者ID:hitswa,项目名称:winforms,代码行数:12,代码来源:converters.cs

示例4: CheckStandardValues

		public void CheckStandardValues(object[] expected, TypeConverter conv) {
			TypeConverter.StandardValuesCollection	values;

			values = conv.GetStandardValues(null);

			if (values == null && expected != null) {
				failed++;
				if (verbose > 0) {
					Console.WriteLine("{0}: GetStandardValues expected {0} values, got null", conv.ToString(), expected.Length);
				}
				return;
			}

			if (values != null && expected == null) {
				failed++;
				if (verbose > 0) {
					Console.WriteLine("{0}: GetStandardValues expected no values, got {1} values", conv.ToString(), values.Count);
				}
				return;
			}

			if (values != null) {
				if (values.Count != expected.Length) {
					if (verbose > 0) {
						Console.WriteLine("{0} GetStandardValues expected {1} values, returned {2}", conv.ToString(), expected.Length, values.Count);
					}
					failed++;
				}

				if (debug > 0) {
					Console.WriteLine("{0} Got {1} standard values", conv.ToString(), values.Count);
				}

				for (int i = 0; i < Math.Min(values.Count, expected.Length); i++) {
					if (debug > 0) {
						Console.WriteLine("{0}: Index {1:2} expecting:{2}, returned {3}", conv.ToString(), i, expected[i], values[i]);
					}

					if (!expected[i].Equals(values[i].ToString())) {
						if (verbose > 0) {
							Console.WriteLine("{0}: GetStandardValues Index {1} values don't match ({2} != {3})", conv.ToString(), i, expected[i], values[i]);
						}
						failed++;

					}
				}
			}
		}
开发者ID:hitswa,项目名称:winforms,代码行数:48,代码来源:converters.cs


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