Example #1
0
        /// <summary>
        /// Sets the property value of the given object.
        /// </summary>
        /// <param name="obj">The target object.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">The property value.</param>
        public static void Set(object obj, string propertyName, object value)
        {
            Guard.ArgumentNotNullOrEmpty(obj, "obj");
            Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
            PropertyAccessor    propertyAccessor;
            PropertyAccessorKey key = new PropertyAccessorKey(obj.GetType(), propertyName);

            if (propertyAccessors.ContainsKey(key))
            {
                propertyAccessor = propertyAccessors[key];
                propertyAccessor.Set(obj, value);
                return;
            }
            lock (synchHelper)
            {
                if (propertyAccessors.ContainsKey(key))
                {
                    propertyAccessor = propertyAccessors[key];
                    propertyAccessor.Set(obj, value);
                    return;
                }
                propertyAccessor       = new PropertyAccessor(obj.GetType(), propertyName);
                propertyAccessors[key] = propertyAccessor;
            }
            propertyAccessor.Set(obj, value);
        }
Example #2
0
 /// <summary>
 /// Sets the property value of the given object.
 /// </summary>
 /// <param name="obj">The target object.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="value">The property value.</param>
 public static void Set(T obj, string propertyName, object value)
 {
     Guard.ArgumentNotNullOrEmpty(obj, "obj");
     Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
     PropertyAccessor.Set(obj, propertyName, value);
 }