TypeConverter.ConvertFromInvariantString 方法

定義

會使用不因文化特性而異,將值轉換為這個轉換子的型別。

多載

ConvertFromInvariantString(String)

會使用不因文化特性而異,將指定字串轉換為這個轉換子的型別。

ConvertFromInvariantString(ITypeDescriptorContext, String)

會使用不區分的文化特性和指定的內容,將指定的字串轉換為這個轉換子的型別。

ConvertFromInvariantString(String)

來源:
TypeConverter.cs
來源:
TypeConverter.cs
來源:
TypeConverter.cs

會使用不因文化特性而異,將指定字串轉換為這個轉換子的型別。

C#
public object ConvertFromInvariantString (string text);
C#
public object? ConvertFromInvariantString (string text);

參數

text
String

要進行轉換的 String

傳回

表示轉換文字的 Object

例外狀況

無法執行轉換作業。

備註

預設的實作 (Implementation) 一定會傳回 null

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ConvertFromInvariantString(ITypeDescriptorContext, String)

來源:
TypeConverter.cs
來源:
TypeConverter.cs
來源:
TypeConverter.cs

會使用不區分的文化特性和指定的內容,將指定的字串轉換為這個轉換子的型別。

C#
public object ConvertFromInvariantString (System.ComponentModel.ITypeDescriptorContext context, string text);
C#
public object? ConvertFromInvariantString (System.ComponentModel.ITypeDescriptorContext? context, string text);

參數

context
ITypeDescriptorContext

提供格式內容的 ITypeDescriptorContext

text
String

要進行轉換的 String

傳回

表示轉換文字的 Object

例外狀況

無法執行轉換作業。

備註

如果字串無法轉換成適當的物件,就會引發例外狀況。 預設的實作 (Implementation) 一定會傳回 null

context 參數可以用於擷取環境的其他資訊,而這個轉換子就是從該環境叫用的。 此參數可以是 null,因此請一律檢查它。 甚至,內容物件上的屬性可能會傳回 null

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1