Export (0) Print
Expand All

FontNamesConverter.CanConvertFrom Method (ITypeDescriptorContext, Type)

Determines whether this converter can convert an object of the specified data type to an array of strings containing individual font names.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public override bool CanConvertFrom(
	ITypeDescriptorContext context,
	Type sourceType
)

Parameters

context
Type: System.ComponentModel.ITypeDescriptorContext

A System.ComponentModel.ITypeDescriptorContext object that provides information about the context of a type converter. You can optionally pass in null for this parameter.

sourceType
Type: System.Type

A System.Type that represents the data type to convert from.

Return Value

Type: System.Boolean
true if the type can be converted; otherwise, false.

Use the CanConvertFrom method to determine whether the specified data type can be converted to an array of strings containing individual font names.

NoteNote

This converter can convert only from a string data type. The sourceType parameter must be of type String. Otherwise, this method returns false to indicate that the specified data type cannot be converted.

You can optionally pass in null for the context parameter.

The following code example demonstrates how to use the CanConvertFrom method. 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>
   

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft