Beispiel #1
0
        /// <summary>
        /// Sets a parameter value.
        /// </summary>
        /// <param name="command">The command with the parameter.</param>
        /// <param name="parameterName">The parameter name.</param>
        /// <param name="value">The parameter value.</param>
        public override void SetParameterValue(DbCommand command, string parameterName, object value)
        {
            object convertedValue = value;

            ParameterTypeRegistry registry = GetParameterTypeRegistry(command.CommandText);

            if (registry != null)
            {
                if (registry.HasRegisteredParameterType(parameterName))
                {
                    DbType dbType = registry.GetRegisteredParameterType(parameterName);

                    if (DbType.Guid == dbType)
                    {
                        convertedValue = ConvertGuidToByteArray(value);
                    }
                    else if (DbType.Boolean == dbType)
                    {
                        convertedValue = ConvertBoolToShort(value);
                    }
                }
            }

            base.SetParameterValue(command, parameterName, convertedValue);
        }
Beispiel #2
0
        /// <summary>
        /// Gets a parameter value.
        /// </summary>
        /// <param name="command">The command that contains the parameter.</param>
        /// <param name="name">The name of the parameter.</param>
        /// <returns>The value of the parameter.</returns>
        public override object GetParameterValue(DbCommand command, string name)
        {
            object convertedValue = base.GetParameterValue(command, name);

            ParameterTypeRegistry registry = GetParameterTypeRegistry(command.CommandText);

            if (registry != null)
            {
                if (registry.HasRegisteredParameterType(name))
                {
                    DbType dbType = registry.GetRegisteredParameterType(name);

                    if (DbType.Guid == dbType)
                    {
                        convertedValue = ConvertByteArrayToGuid(convertedValue);
                    }
                    else if (DbType.Boolean == dbType)
                    {
                        convertedValue = ConvertShortToBool(convertedValue);
                    }
                }
            }

            return(convertedValue);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the parameter type registry for the specified command.
        /// </summary>
        /// <param name="commandText">The command text.</param>
        /// <returns>Existing or new registry</returns>
        private ParameterTypeRegistry GetParameterTypeRegistry(string commandText)
        {
            ParameterTypeRegistry registry;

            registeredParameterTypes.TryGetValue(commandText, out registry);
            if (registry == null)
            {
                registry = new ParameterTypeRegistry();
                registeredParameterTypes.Add(commandText, registry);
            }

            return(registry);
        }
Beispiel #4
0
        /// <summary>
        /// Registers the type of the parameter in a parameter registry.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="parameterName">Name of the parameter.</param>
        /// <param name="dbType">Type of the parameter.</param>
        private void RegisterParameterType(DbCommand command, string parameterName, DbType dbType)
        {
            ParameterTypeRegistry registry = GetParameterTypeRegistry(command.CommandText);

            registry.RegisterParameterType(parameterName, dbType);
        }