本文整理匯總了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++;
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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++;
}
}
}
}