FontNamesConverter.CanConvertFrom(ITypeDescriptorContext, Type) FontNamesConverter.CanConvertFrom(ITypeDescriptorContext, Type) FontNamesConverter.CanConvertFrom(ITypeDescriptorContext, Type) FontNamesConverter.CanConvertFrom(ITypeDescriptorContext, Type) Method

Definition

Bestimmt, ob dieser Konverter ein Objekt des angegebenen Datentyps in ein Array von Zeichenfolgen mit einzelnen Schriftartnamen konvertieren kann.Determines whether this converter can convert an object of the specified data type to an array of strings containing individual font names.

public:
 override bool CanConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ context, Type ^ sourceType);
public override bool CanConvertFrom (System.ComponentModel.ITypeDescriptorContext context, Type sourceType);
override this.CanConvertFrom : System.ComponentModel.ITypeDescriptorContext * Type -> bool
Public Overrides Function CanConvertFrom (context As ITypeDescriptorContext, sourceType As Type) As Boolean

Parameter

context
ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext

Ein ITypeDescriptorContext-Objekt, das Informationen über den Kontext eines Typkonverters bereitstellt.A ITypeDescriptorContext object that provides information about the context of a type converter. Für diesen Parameter kann optional null übergeben werden.You can optionally pass in null for this parameter.

sourceType
Type Type Type Type

Ein Type, der den Ausgangsdatentyp der Konvertierung darstellt.A Type that represents the data type to convert from.

Gibt zurück

true, wenn der Typ konvertiert werden kann, andernfalls false.true if the type can be converted; otherwise, false.

Beispiele

Das folgende Codebeispiel zeigt, wie Sie die CanConvertFrom-Methode verwenden.The following code example demonstrates how to use the CanConvertFrom method. Im Beispiel wird bestimmt, ob der angegebene Datentyp in ein Zeichen folgen Array konvertiert werden kann, das die einzelnen Schriftart Namen enthält, bevor die Konvertierung durchgeführt wird.The example determines whether the specified data type can be converted to an array of strings that contains the individual font names before performing the conversion.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>FontNamesConverter Example</title>
<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>
   <br />

   <form id="form1" 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>
   
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>FontNamesConverter Example</title>
<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>
   <br />

   <form id="form1" 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>
   

Hinweise

Verwenden Sie CanConvertFrom die-Methode, um zu bestimmen, ob der angegebene Datentyp in ein Zeichen folgen Array konvertiert werden kann, das einzelne Schriftart Namen enthält.Use the CanConvertFrom method to determine whether the specified data type can be converted to an array of strings containing individual font names.

Hinweis

Dieser Konverter kann nur von einem string Datentyp konvertieren.This converter can convert only from a string data type. Der sourceType -Parameter muss vom Typ Stringsein.The sourceType parameter must be of type String. Andernfalls gibt diese Methode zurück false , um anzugeben, dass der angegebene Datentyp nicht konvertiert werden kann.Otherwise, this method returns false to indicate that the specified data type cannot be converted.

Optional können Sie null für den context -Parameter übergeben.You can optionally pass in null for the context parameter.

Gilt für:

Siehe auch