Exemple #1
0
        private IDbDataParameter GetParameter(TINSERTOBJECT commandObject, DBParameterAttribute attribute, PropertyInfo property)
        {
            IDbDataParameter parameter = new SqlParameter {
                Direction = attribute.Direction
            };

            attribute.SetParameterValue(commandObject, property, parameter);
            return(parameter);
        }
        public void Initialize()
        {
            if (_Initialized)
            {
                return;
            }

            Dictionary <string, DBParameterAttribute> _attributes = new Dictionary <string, DBParameterAttribute>();
            Dictionary <string, PropertyInfo>         _properties = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo property in typeof(TCOMMAND).GetProperties())
            {
                DBParameterAttribute _attribute = property.GetCustomAttribute <DBParameterAttribute>(true);
                string _key = _attribute.Name;
                _attributes.Add(_key, _attribute);
                _properties.Add(_key, property);
            }

            _Attributes = new DBParameterAttribute[_attributes.Keys.Count];
            _Properties = new PropertyInfo[_attributes.Keys.Count];

            int _index = 0;

            foreach (string key in _attributes.Keys)
            {
                var _attribute = _attributes[key];
                _Attributes[_index] = _attribute;
                _Properties[_index] = _properties[key];

                if (_attribute.Direction == ParameterDirection.InputOutput || _attribute.Direction == ParameterDirection.Output || _attribute.Direction == ParameterDirection.ReturnValue)
                {
                    _OutputParameters.Add(_index);
                }

                _index++;
            }

            CommandAttribute = GetDBCommandAttribute();

            _Initialized = true;
        }