コード例 #1
0
        public void GenerateTypeProjection <T>(DataSetInfo outputInfo)
        {
            var type = typeof(T);

            if (!_typeProjections.ContainsKey(type))
            {
                _typeProjections[type] = new NpgsqlTypeProjection <T>(outputInfo);
            }
        }
コード例 #2
0
        private static Dictionary <string, object> GenerateValues <T>(T row, NpgsqlTypeProjection <T> typeProjection, Dictionary <string, object> valueOverrides, IEnumerable <string> excludeColumns = null)
        {
            var values = typeProjection.TypePropertyProjections.ToDictionary(
                tpp => tpp.ColumnName,
                tpp =>
            {
                switch (tpp.GetPropertyValue(row))
                {
                case string valueStr:
                    return(valueStr.Replace("\u0000", ""));

                case object value:
                    return(value);
                }
                return(null);
            }
                );

            valueOverrides?.ToList().ForEach(kvp =>
            {
                if (values.ContainsKey(kvp.Key))
                {
                    values[kvp.Key] = kvp.Value;
                }
                else
                {
                    values.Add(kvp.Key, kvp.Value);
                }
            });

            if (excludeColumns != null)
            {
                foreach (var excludedColumn in excludeColumns)
                {
                    values.Remove(excludedColumn);
                }
            }

            return(values);
        }