Пример #1
0
        public int SetValues <T>(IKeyValueBag bag, T obj, Func <PropertyInfo, KeyValuePair <string, object>, object> setValueAdapter)
        {
            var type   = typeof(T);
            int misses = 0;
            var props  = type.GetProperties();

            foreach (var pair in bag)
            {
                var p = props.FirstOrDefault(x => x.Name == pair.Key);
                if (p != null)
                {
                    if (setValueAdapter == null)
                    {
                        // Just ram it in there
                        p.SetValue(obj, pair.Value);
                    }
                    else
                    {
                        var adapt = setValueAdapter(p, pair);
                        if (adapt == Skip)
                        {
                            misses++;
                        }
                        else
                        {
                            p.SetValue(obj, adapt);
                        }
                    }
                }
                else
                {
                    misses++;
                }
            }
            return(misses);
        }
Пример #2
0
 public int SetValues <T>(IKeyValueBag bag, T obj) => SetValues(bag, obj, DefaultAdapter);