Esempio n. 1
0
        /// <summary>
        /// Gets the type of the property.
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns></returns>
        public static Type GetPropertyType(Type targetType, string propertyName)
        {
            Guard.ArgumentNotNullOrEmpty(targetType, "targetType");
            Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
            PropertyAccessorKey key = new PropertyAccessorKey(targetType, propertyName);

            if (propertyAccessors.ContainsKey(key))
            {
                return(propertyAccessors[key].PropertyType);
            }
            lock (synchHelper)
            {
                if (propertyAccessors.ContainsKey(key))
                {
                    return(propertyAccessors[key].PropertyType);
                }
                var propertyAccessor = new PropertyAccessor(targetType, propertyName);
                propertyAccessors[key] = propertyAccessor;
                return(propertyAccessor.PropertyType);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the property value of the given object.
        /// </summary>
        /// <param name="obj">The target object.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>The property value of the given object.</returns>
        public static object Get(object obj, string propertyName)
        {
            Guard.ArgumentNotNullOrEmpty(obj, "obj");
            Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
            PropertyAccessor    propertyAccessor;
            PropertyAccessorKey key = new PropertyAccessorKey(obj.GetType(), propertyName);

            if (propertyAccessors.ContainsKey(key))
            {
                propertyAccessor = propertyAccessors[key];
                return(propertyAccessor.Get(obj));
            }
            lock (synchHelper)
            {
                if (propertyAccessors.ContainsKey(key))
                {
                    propertyAccessor = propertyAccessors[key];
                    return(propertyAccessor.Get(obj));
                }
                propertyAccessor       = new PropertyAccessor(obj.GetType(), propertyName);
                propertyAccessors[key] = propertyAccessor;
            }
            return(propertyAccessor.Get(obj));
        }
Esempio n. 3
0
 /// <summary>
 /// Gets the type of the property.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <returns>The type of given property.</returns>
 public static Type GetPropertyType(string propertyName)
 {
     Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
     return(PropertyAccessor.GetPropertyType(typeof(T), propertyName));
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 /// <summary>
 /// Gets the property value of the given object.
 /// </summary>
 /// <param name="obj">The target object.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <returns>The property value of the given object.</returns>
 public static object Get(T obj, string propertyName)
 {
     Guard.ArgumentNotNullOrEmpty(obj, "obj");
     Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
     return(PropertyAccessor.Get(obj, propertyName));
 }