コード例 #1
0
        public static IReadOnlyDictionary <string, object?> ToDictionary(object source, IColumnFormat columnFormat)
        {
            var result = new Dictionary <string, object?>();

            foreach (PropertyDescriptor?property in TypeDescriptor.GetProperties(source))
            {
                if (property is not null)
                {
                    result.Add(columnFormat.Format(property.Name), property.GetValue(source));
                }
            }
            return(result);
        }
コード例 #2
0
        public static T ToObject <T>(IReadOnlyDictionary <string, object?> source, IColumnFormat columnFormat) where T : new()
        {
            var result = new T();

            foreach (PropertyDescriptor?property in TypeDescriptor.GetProperties(result))
            {
                if (property is null || !source.TryGetValue(columnFormat.Format(property.Name), out object?value))
                {
                    continue;
                }

                if (value is null || value == DBNull.Value)
                {
                    SetProperty(result, property, null);
                }
コード例 #3
0
 public void FormatTest(string entityColumn, string expectedDatabaseColumn)
 {
     _columnFormat.Format(entityColumn).Should().Be(expectedDatabaseColumn);
 }