このコンバータで指定されたデータ型のオブジェクトを、個別のフォント名を含んでいる文字列の配列に変換できるかどうかを確認します。
Overrides Overloads Public Function CanConvertFrom( _
ByVal context As ITypeDescriptorContext, _ ByVal sourceType As Type _) As Boolean
[C#]
public override bool CanConvertFrom(ITypeDescriptorContextcontext,TypesourceType);
[C++]
public: bool CanConvertFrom(ITypeDescriptorContext* context,Type* sourceType);
[JScript]
public override function CanConvertFrom(
context : ITypeDescriptorContext,sourceType : Type) : Boolean;
パラメータ
- context
型コンバータのコンテキストに関する情報を提供する System.ComponentModel.ITypeDescriptorContext 。このパラメータには、 null 参照 (Visual Basic では Nothing) を渡すこともできます。 - sourceType
変換前のデータ型を表す System.Type 。
戻り値
型を変換できる場合は true 。それ以外の場合は false 。
解説
CanConvertFrom メソッドを使用して、指定されたデータ型を、個別のフォント名を含んでいる文字列の配列に変換できるかどうかを確認します。
メモ このコンバータは string データ型からの変換だけを実行できます。 sourceType パラメータは、string データ型である必要があります。それ以外の場合、このメソッドは false を返して、指定したデータ型を変換できないことを示します。
context パラメータには、 null 参照 (Visual Basic では Nothing) を渡すこともできます。
使用例
[Visual Basic, C#] CanConvertFrom メソッドを使用して、変換を実行する前に、指定されたデータ型を個別のフォント名を含んでいる文字列の配列に変換できるかどうかを確認する方法の例を次に示します。
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Declare local variables.
Dim culture As New System.Globalization.CultureInfo("en")
Dim context As System.ComponentModel.ITypeDescriptorContext = Nothing
Dim names As Object
Dim name_string As Object
' Create FontNamesConverter object.
Dim fontconverter As New FontNamesConverter()
' Create original list of fonts.
Dim font_list As String = "arial, times new roman, verdana"
' Check for type compatibility.
If fontconverter.CanConvertFrom(context, GetType(String)) Then
' Display original string.
Label1.Text = "Original String :" & "<br><br>" & font_list
' Convert string to array to strings and display results.
names = fontconverter.ConvertFrom(context, culture, font_list)
Label2.Text = "Converted to Array of Strings : " & "<br><br>"
Dim name_element As String
For Each name_element In CType(names, String())
Label2.Text &= name_element & "<br>"
Next name_element
' Convert array of strings back to a string and display results.
name_string = fontconverter.ConvertTo(context, culture, names, _
GetType(String))
Label3.Text = "Converted back to String :" & "<br><br>" & _
CType(name_string, String)
End If
End Sub 'Page_Load
</script>
</head>
<body>
<h3>FontNamesConverter Example</h3>
<p>
<form runat=server>
<asp:Label id="Label1" runat="server"/>
<br><hr>
<asp:Label id="Label2" runat="server"/>
<br><hr>
<asp:Label id="Label3" runat="server"/>
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Declare local variables.
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en");
System.ComponentModel.ITypeDescriptorContext context = null;
Object names;
Object name_string;
// Create FontNamesConverter object.
FontNamesConverter fontconverter = new FontNamesConverter();
// Create original list of fonts.
string font_list = "arial, times new roman, verdana";
// Check for type compatibility.
if (fontconverter.CanConvertFrom(context, typeof(string)))
{
// Display original string.
Label1.Text = "Original String :" + "<br><br>" + font_list;
// Convert string to array to strings and display results.
names = fontconverter.ConvertFrom(context, culture, font_list);
Label2.Text = "Converted to Array of Strings : " + "<br><br>";
foreach (string name_element in (string[])names)
{
Label2.Text += name_element + "<br>";
}
// Convert array of strings back to a string and display results.
name_string = fontconverter.ConvertTo(context, culture, names, typeof(string));
Label3.Text = "Converted back to String :" + "<br><br>" + (string)name_string;
}
}
</script>
</head>
<body>
<h3>FontNamesConverter Example</h3>
<p>
<form runat=server>
<asp:Label id="Label1" runat="server"/>
<br><hr>
<asp:Label id="Label2" runat="server"/>
<br><hr>
<asp:Label id="Label3" runat="server"/>
</form>
</body>
</html>
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
FontNamesConverter クラス | FontNamesConverter メンバ | System.Web.UI.WebControls 名前空間 | FontNamesConverter.CanConvertFrom オーバーロードの一覧 | System.ComponentModel.ITypeDescriptorContext | System.Type | ConvertFrom | ConvertTo