Ejemplo n.º 1
0
            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                if (destinationType == null)
                {
                    throw ADP.ArgumentNull("destinationType");
                }
                if ((destinationType == typeof(InstanceDescriptor)) && (value is OdbcParameter))
                {
                    object[]      objArray3;
                    Type[]        typeArray3;
                    OdbcParameter parameter = (OdbcParameter)value;
                    int           num       = 0;
                    if (OdbcType.NChar != parameter.OdbcType)
                    {
                        num |= 1;
                    }
                    if (parameter.ShouldSerializeSize())
                    {
                        num |= 2;
                    }
                    if (!ADP.IsEmpty(parameter.SourceColumn))
                    {
                        num |= 4;
                    }
                    if (parameter.Value != null)
                    {
                        num |= 8;
                    }
                    if (((ParameterDirection.Input != parameter.Direction) || parameter.IsNullable) || ((parameter.ShouldSerializePrecision() || parameter.ShouldSerializeScale()) || (DataRowVersion.Current != parameter.SourceVersion)))
                    {
                        num |= 0x10;
                    }
                    if (parameter.SourceColumnNullMapping)
                    {
                        num |= 0x20;
                    }
                    switch (num)
                    {
                    case 0:
                    case 1:
                        typeArray3 = new Type[] { typeof(string), typeof(OdbcType) };
                        objArray3  = new object[] { parameter.ParameterName, parameter.OdbcType };
                        break;

                    case 2:
                    case 3:
                        typeArray3 = new Type[] { typeof(string), typeof(OdbcType), typeof(int) };
                        objArray3  = new object[] { parameter.ParameterName, parameter.OdbcType, parameter.Size };
                        break;

                    case 4:
                    case 5:
                    case 6:
                    case 7:
                        typeArray3 = new Type[] { typeof(string), typeof(OdbcType), typeof(int), typeof(string) };
                        objArray3  = new object[] { parameter.ParameterName, parameter.OdbcType, parameter.Size, parameter.SourceColumn };
                        break;

                    case 8:
                        typeArray3 = new Type[] { typeof(string), typeof(object) };
                        objArray3  = new object[] { parameter.ParameterName, parameter.Value };
                        break;

                    default:
                        if ((0x20 & num) == 0)
                        {
                            typeArray3 = new Type[] { typeof(string), typeof(OdbcType), typeof(int), typeof(ParameterDirection), typeof(bool), typeof(byte), typeof(byte), typeof(string), typeof(DataRowVersion), typeof(object) };
                            objArray3  = new object[] { parameter.ParameterName, parameter.OdbcType, parameter.Size, parameter.Direction, parameter.IsNullable, parameter.PrecisionInternal, parameter.ScaleInternal, parameter.SourceColumn, parameter.SourceVersion, parameter.Value };
                        }
                        else
                        {
                            typeArray3 = new Type[] { typeof(string), typeof(OdbcType), typeof(int), typeof(ParameterDirection), typeof(byte), typeof(byte), typeof(string), typeof(DataRowVersion), typeof(bool), typeof(object) };
                            objArray3  = new object[] { parameter.ParameterName, parameter.OdbcType, parameter.Size, parameter.Direction, parameter.PrecisionInternal, parameter.ScaleInternal, parameter.SourceColumn, parameter.SourceVersion, parameter.SourceColumnNullMapping, parameter.Value };
                        }
                        break;
                    }
                    ConstructorInfo constructor = typeof(OdbcParameter).GetConstructor(typeArray3);
                    if (null != constructor)
                    {
                        return(new InstanceDescriptor(constructor, objArray3));
                    }
                }
                return(base.ConvertTo(context, culture, value, destinationType));
            }