Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TypeConverter

Status
Not open for further replies.

Morpheus1981

Programmer
Aug 9, 2001
105
CR
I am trying to create my own typeconverter. I am trying to convert a type object to SQLConnection, I know this does not make much sence, But it is important to me do it in this way.
At bottom is all what I've been able to do, I've notice it that sourceType and destinationType always are string type. Besides that I know nothing else.

Please take me to the right way.

Thanks!


using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.ComponentModel;


namespace STDControlLib
{
using System;
using System.ComponentModel;
using System.Globalization;
using System.Drawing;

public class ConnectionConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if ((sourceType == typeof(string)) || (sourceType == typeof(object)))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
object obj = value;

if ((value is string))
{
object sql= base.ConvertFromString((string)value);
return sql;
}
return base.ConvertFrom(context, culture, value);
}

public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return "Hola";
}
else
return destinationType.ToString();
//return base.ConvertTo(context, culture, value, destinationType);
}


/*public object ConvertFromString(string text)
{
return base.ConvertFromString(text);
}*/

}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top