Apache.NMS.Util.URISupport.SetProperties C# (CSharp) Method

SetProperties() public static method

Sets the public properties of a target object using a string map. This method uses .Net reflection to identify public properties of the target object matching the keys from the passed map.
public static SetProperties ( object target, StringDictionary map ) : void
target object The object whose properties will be set.
map System.Collections.Specialized.StringDictionary Map of key/value pairs.
return void
        public static void SetProperties(object target, StringDictionary map)
        {
            Type type = target.GetType();

            foreach(string key in map.Keys)
            {
                PropertyInfo prop = type.GetProperty(key,
                                                        BindingFlags.FlattenHierarchy
                                                        | BindingFlags.Public
                                                        | BindingFlags.Instance
                                                        | BindingFlags.IgnoreCase);

                if(null != prop)
                {
                    prop.SetValue(target, Convert.ChangeType(map[key], prop.PropertyType, CultureInfo.InvariantCulture), null);
                }
                else
                {
                    FieldInfo field = type.GetField(key,
                                                        BindingFlags.FlattenHierarchy
                                                        | BindingFlags.Public
                                                        | BindingFlags.Instance
                                                        | BindingFlags.IgnoreCase);
                    if(null != field)
                    {
                        field.SetValue(target, Convert.ChangeType(map[key], field.FieldType, CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        throw new NMSException(string.Format("No such property or field: {0} on class: {1}", key, target.GetType().Name));
                    }
                }
            }
        }

Same methods

URISupport::SetProperties ( object target, StringDictionary map, string prefix ) : void