예제 #1
0
        // returns the value
        // if the user specified a type it will try to convert the value to the specified type
        //
        // in addition this will set this._bindtype
        //
        private object GetParameterValue()
        {
            object value = Value;

            if (_userSpecifiedType)
            {
                if ((null != value) && !Convert.IsDBNull(value))
                {
                    Type vt = value.GetType();
                    if (!vt.IsArray && (vt != _typemap._type))
                    {
                        value = Convert.ChangeType(value, _typemap._type);
                    }
                }
            }
            else if (null == _typemap)
            {
                if ((null == value) || Convert.IsDBNull(value))
                {
                    _typemap = TypeMap._NVarChar; // default type
                }
                else
                {
                    _typemap = TypeMap.FromSystemType(value.GetType());
                }
            }
            Debug.Assert(null != _typemap, "GetParameterValue: null _typemap");
            _originalbindtype = _bindtype = _typemap;
            return(value);
        }
예제 #2
0
        private object ProcessAndGetParameterValue()
        {
            object value = _internalValue;

            if (_internalUserSpecifiedType)
            {
                if ((null != value) && !Convert.IsDBNull(value))
                {
                    Type valueType = value.GetType();
                    if (!valueType.IsArray)
                    {
                        if (valueType != _typemap._type)
                        {
                            try
                            {
                                value = Convert.ChangeType(value, _typemap._type, (System.IFormatProvider)null);
                            }
                            catch (Exception e)
                            {
                                // Don't know which exception to expect from ChangeType so we filter out the serious ones
                                //
                                if (!ADP.IsCatchableExceptionType(e))
                                {
                                    throw;
                                }
                                throw ADP.ParameterConversionFailed(value, _typemap._type, e); // WebData 75433
                            }
                        }
                    }
                    else if (valueType == typeof(char[]))
                    {
                        value = new string((char[])value);
                    }
                }
            }
            else if (null == _typemap)
            {
                if ((null == value) || Convert.IsDBNull(value))
                {
                    _typemap = TypeMap._NVarChar; // default type
                }
                else
                {
                    Type type = value.GetType();

                    _typemap = TypeMap.FromSystemType(type);
                }
            }
            Debug.Assert(null != _typemap, "GetParameterValue: null _typemap");
            _originalbindtype = _bindtype = _typemap;
            return(value);
        }
예제 #3
0
        private object ProcessAndGetParameterValue()
        {
            object obj2 = this._internalValue;

            if (this._internalUserSpecifiedType)
            {
                if ((obj2 != null) && !Convert.IsDBNull(obj2))
                {
                    Type type = obj2.GetType();
                    if (!type.IsArray)
                    {
                        if (!(type != this._typemap._type))
                        {
                            goto Label_00D5;
                        }
                        try
                        {
                            obj2 = Convert.ChangeType(obj2, this._typemap._type, null);
                            goto Label_00D5;
                        }
                        catch (Exception exception)
                        {
                            if (!ADP.IsCatchableExceptionType(exception))
                            {
                                throw;
                            }
                            throw ADP.ParameterConversionFailed(obj2, this._typemap._type, exception);
                        }
                    }
                    if (type == typeof(char[]))
                    {
                        obj2 = new string((char[])obj2);
                    }
                }
            }
            else if (this._typemap == null)
            {
                if ((obj2 == null) || Convert.IsDBNull(obj2))
                {
                    this._typemap = TypeMap._NVarChar;
                }
                else
                {
                    Type dataType = obj2.GetType();
                    this._typemap = TypeMap.FromSystemType(dataType);
                }
            }
Label_00D5:
            this._originalbindtype = this._bindtype = this._typemap;
            return(obj2);
        }