Export (0) Print
Expand All

FontNamesConverter.ConvertTo Method (ITypeDescriptorContext, CultureInfo, Object, Type)

Creates a string that represents a list of font names from an array of strings containing individual font names.

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

public override Object ConvertTo(
	ITypeDescriptorContext context,
	CultureInfo culture,
	Object value,
	Type destinationType
)

Parameters

context
Type: System.ComponentModel.ITypeDescriptorContext

A System.ComponentModel.ITypeDescriptorContext object that provides information about the context of a type converter. This parameter is not used in this method. It is reserved for future versions of this method. You can optionally pass in null for this parameter.

culture
Type: System.Globalization.CultureInfo

A System.Globalization.CultureInfo object that represents information about a culture such as language, calendar system, and so on. This parameter is not used in this method. It is reserved for future versions of this method. You can optionally pass in null for this parameter.

value
Type: System.Object

An object that represents the source array of strings to convert from.

destinationType
Type: System.Type

A System.Object instance object that represents the data type to convert to. This parameter must be of type String.

Return Value

Type: System.Object
A System.Object instance that represents a string containing a list of font names.

ExceptionCondition
GetConvertToException

destinationType is not of type String.

Use the ConvertTo method to convert an array of strings containing the individual font names to a single string containing a list of the names. For example, an array that contains the strings "arial", "times new roman", and "verdana" converts to the string "arial,times new roman,verdana". Notice that commas are automatically inserted between the font names without any white space.

NoteNote

This converter can convert only to a string data type. The destinationType parameter must be of type String.

NoteNote

The context and culture parameters are not used in this version of the method; they are reserved for future versions of the method. You can optionally pass in null for these parameters.

The following code example demonstrates how to use the ConvertTo method to convert an array of strings containing the individual names to a single string that contains a list of font names.

<%@ 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
Show:
© 2015 Microsoft