Esempio n. 1
0
        public static void PutPropertyValuesToObject(object o, PropertyValueCollection values, HandleSpecialValueMappingDelegate specialMappingHandler,
                                                     string[] ignoreProps)
        {
            if (ignoreProps == null)
            {
                ignoreProps = new string[] { "" }
            }
            ;
            PropertyInfo[] targetObjectProps = o.GetType().GetProperties();

            foreach (string key in values.Keys.ToArray())
            {
                if (targetObjectProps.Any(p => p.Name.Equals(key, StringComparison.InvariantCultureIgnoreCase) && p.CanWrite))
                {
                    object newValue = values[key];
                    if (specialMappingHandler != null)
                    {
                        newValue = specialMappingHandler(key, newValue) ?? newValue;
                    }

                    if (!ignoreProps.Contains(key))
                    {
                        try
                        {
                            PropertyInfo prop = targetObjectProps.Single(p => p.Name.Equals(key, StringComparison.InvariantCultureIgnoreCase) && p.CanWrite);
                            prop.SetValue(o, newValue, null);
                        }
                        catch { }
                    }

                    values.Remove(key);
                }
            }
        }
Esempio n. 2
0
 public void PutPropertyValuesToObject(object o, HandleSpecialValueMappingDelegate specialMappingHandler, string[] ignoreProps)
 {
     PutPropertyValuesToObject(o, this, specialMappingHandler, ignoreProps);
 }