Ejemplo n.º 1
0
        /// <summary>
        /// Gets the default compare method.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>CompareMethod.</returns>
        private static CompareMethod GetDefaultCompareMethod(Type type)
        {
            var result = Comparison.Equal;

            if (type == typeof(string))
            {
                result = CompareMethod.Contains;
            }
            else if (type == typeof(DateTime) || SusanooCommander.GetDbType(type) == null)
            {
                result = CompareMethod.Ignore;
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines whether this deserializer applies to the type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns><c>true</c> if this instance can deserialize; otherwise, <c>false</c>.</returns>
 public bool CanDeserialize(Type type)
 {
     return(SusanooCommander.GetDbType(type) != null);
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Builds the property inclusion parameters.
        /// </summary>
        /// <param name="databaseManager">The database manager.</param>
        /// <param name="filter">The filter.</param>
        /// <returns>IEnumerable&lt;DbParameter&gt;.</returns>
        public virtual IEnumerable <DbParameter> BuildPropertyParameters(IDatabaseManager databaseManager, object filter)
        {
            var parameters = new List <DbParameter>();

            if (typeof(TFilter).GetTypeInfo().IsValueType || filter != null)
            {
                if (_explicitInclusionMode)
                {
                    foreach (var item in _parameterInclusions)
                    {
                        var propInfo = filter.GetType().GetTypeInfo()
                                       .GetProperty(item.Key, BindingFlags.Instance | BindingFlags.Public);
                        var param = databaseManager.CreateParameter();

                        param.SourceColumn  = propInfo.Name;
                        param.ParameterName = item.Key;
                        param.Direction     = ParameterDirection.Input;

#if !NETFX40
                        param.Value = propInfo.GetValue(filter);
#else
                        param.Value = propInfo.GetValue(filter, null);
#endif

                        var type = SusanooCommander.GetDbType(propInfo.PropertyType);

                        if (type.HasValue)
                        {
                            param.DbType = type.Value;
                        }

                        var value = item.Value;
                        if (value != null)
                        {
                            value.Invoke(param);
                            if (_nullValueMode == NullValueMode.FilterOnlyFull ||
                                _nullValueMode == NullValueMode.Full)
                            {
                                param.Value = ReplaceNullWithDbNull(param.Value);
                            }
                        }
                        else if (_nullValueMode == NullValueMode.FilterOnlyMinimum ||
                                 _nullValueMode == NullValueMode.FilterOnlyFull ||
                                 _nullValueMode == NullValueMode.Full)
                        {
                            param.Value = ReplaceNullWithDbNull(param.Value);
                        }

                        parameters.Add(param);
                    }
                }
                else
                {
                    var implicitProperties = _propertyMetadataExtractor
                                             .FindAllowedProperties(
                        filter.GetType().GetTypeInfo(),
                        DescriptorActions.Insert | DescriptorActions.Update | DescriptorActions.Delete,
                        _parameterInclusions.Select(p => p.Key).ToArray(),
                        _parameterExclusions.ToArray());

                    foreach (var propInfo in implicitProperties)
                    {
                        if (!_parameterExclusions.Contains(propInfo.Value.ActiveAlias))
                        {
                            var param = databaseManager.CreateParameter();

                            param.SourceColumn  = propInfo.Key.Name;
                            param.ParameterName = propInfo.Value.ActiveAlias;
                            param.Direction     = ParameterDirection.Input;
#if !NETFX40
                            param.Value = propInfo.Key.GetValue(filter);
#else
                            param.Value = propInfo.Key.GetValue(filter, null);
#endif

                            var type = SusanooCommander.GetDbType(propInfo.Key.PropertyType);

                            if (type.HasValue)
                            {
                                param.DbType = type.Value;
                            }

                            Action <DbParameter> value;
                            if (_parameterInclusions.TryGetValue(propInfo.Value.ActiveAlias, out value))
                            {
                                if (value != null)
                                {
                                    value.Invoke(param);
                                    if (_nullValueMode == NullValueMode.FilterOnlyFull ||
                                        _nullValueMode == NullValueMode.Full)
                                    {
                                        param.Value = ReplaceNullWithDbNull(param.Value);
                                    }
                                }
                                else if (_nullValueMode == NullValueMode.FilterOnlyMinimum ||
                                         _nullValueMode == NullValueMode.FilterOnlyFull ||
                                         _nullValueMode == NullValueMode.Full)
                                {
                                    param.Value = ReplaceNullWithDbNull(param.Value);
                                }
                            }
                            else
                            {
                                if (type == null)
                                {
                                    continue; //If we don't know what to do with the Type of the property
                                }
                                //and there isn't a explicit inclusion of the property, then ignore it.

                                if (_nullValueMode == NullValueMode.FilterOnlyMinimum ||
                                    _nullValueMode == NullValueMode.FilterOnlyFull ||
                                    _nullValueMode == NullValueMode.Full)
                                {
                                    param.Value = ReplaceNullWithDbNull(param.Value);
                                }
                            }

                            parameters.Add(param);
                        }
                    }
                }
            }

            return(parameters);
        }