Пример #1
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));
        }
Пример #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(T obj, string propertyName)
 {
     Guard.ArgumentNotNullOrEmpty(obj, "obj");
     Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName");
     return(PropertyAccessor.Get(obj, propertyName));
 }