Yes I tried even that way. But it didn't help.
Solution to this will make me
I am not getting Int32 converted to Int16
I am sending my code
using System;
using System.Text;
using System.ComponentModel;
using Oracle.DataAccess.Client;
namespace DBType2NETType.TypeConverters
{
public class NumberToInt : TypeConverter
{
public NumberToInt ()
{
}
public override bool CanConvertFrom( ITypeDescriptorContext context, Type sourceType )
{
switch ( sourceType.FullName )
{
case "System.Int64":
case "System.Int32":
return true;
default:
return false;
}
}
public override bool CanConvertTo( ITypeDescriptorContext context, Type destinationType )
{
switch ( destinationType.FullName )
{
case "System.Int32":
case "System.Int16":
return true;
default:
return false;
}
}
public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value )
{
int returnValueInt = 0;
short returnValueShort = 0;
switch ( value.GetType().FullName )
{
case "System.Int64":
returnValueInt = Convert.ToInt32(value);
return returnValueInt;
case "System.Int32":
returnValueShort = Convert.ToInt16(value);
return returnValueShort;
default:
throw new NotSupportedException( "Conversion from a value of type '" + value.GetType().ToString() + "' to System.Int32 isn't supported" );
}
}
public override object ConvertTo( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType )
{
int requiredValueInt = 0;
short requiredValueShort = 0;
if ( value == null )
{
throw new ArgumentNullException( "value", "Value can't be null" );
}
// if ( !( value is Int32) )
// {
// throw new ArgumentException( "Value isn't of type Int32", "value" );
// }
switch ( destinationType.FullName )
{
case "System.Int32":
requiredValueInt = Convert.ToInt32(value);
return requiredValueInt;
case "System.Int16":
requiredValueShort = Convert.ToInt16(value);
return requiredValueShort;
default:
throw new NotSupportedException( "Conversion to a value of type '" + destinationType.ToString() + "' isn't supported" );
}
}
public override object CreateInstance( ITypeDescriptorContext context, System.Collections.IDictionary propertyValues )
{
return 0;
}
}
}