public static object Get(object obj, string propertyName) { PropertyAccessor accessor; Guard.ArgumentNotNullOrEmpty(obj, "obj"); Guard.ArgumentNotNullOrEmpty(propertyName, "propertyName"); PropertyAccessorKey key = new PropertyAccessorKey(obj.GetType(), propertyName); if (propertyAccessors.ContainsKey(key)) { accessor = propertyAccessors[key]; return(accessor.Get(obj)); } lock (synchHelper) { if (propertyAccessors.ContainsKey(key)) { accessor = propertyAccessors[key]; return(accessor.Get(obj)); } accessor = new PropertyAccessor(obj.GetType(), propertyName); propertyAccessors[key] = accessor; } return(accessor.Get(obj)); }
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); } PropertyAccessor accessor = new PropertyAccessor(targetType, propertyName); propertyAccessors[key] = accessor; return(accessor.PropertyType); } }