Morpheus1981
Programmer
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);
}*/
}
}
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);
}*/
}
}