/// <summary>
        /// Gets the recorded value for the given property from {TObject} or an anonymous
        ///  value if there isn't one specified.
        /// </summary>
        /// <typeparam name="TValue">The type of the property</typeparam>
        /// <param name="property">A lambda expression specifying the property to retrieve the recorded value for</param>
        /// <returns>The recorded value of the property or an anonymous value for it</returns>
        public TValue Get <TValue>(Expression <Func <TObject, TValue> > property)
        {
            if (!Has(property))
            {
                return(Any.Get(property));
            }

            return((TValue)_properties[PropertyNameGetter.Get(property)]);
        }
Exemple #2
0
        /// <summary>
        /// Automatically generate an anonymous value for the given property expression.
        /// </summary>
        /// <typeparam name="TObject">The type of the parent object of the property</typeparam>
        /// <typeparam name="T">The type of the property</typeparam>
        /// <param name="property">The expression identifying the property</param>
        /// <returns>The anonymous value, taking into account any registered conventions</returns>
        public T Get <TObject, T>(Expression <Func <TObject, T> > property)
        {
            var propertyName  = PropertyNameGetter.Get(property);
            var valueSupplier = LocalValueSuppliers
                                .Concat(GlobalValueSuppliers)
                                .Concat(DefaultValueSuppliers)
                                .First(s => s.CanSupplyValue <TObject, T>(propertyName));

            return(valueSupplier.GenerateAnonymousValue <TObject, T>(this, propertyName));
        }
 /// <summary>
 /// Returns whether or not there is currently an explicit value recorded against the given property from {TObject}.
 /// </summary>
 /// <typeparam name="TValue">The type of the property</typeparam>
 /// <param name="property">A lambda expression specifying the property to retrieve the recorded value for</param>
 /// <returns>Whether or not there is a recorded value for the property</returns>
 protected bool Has <TValue>(Expression <Func <TObject, TValue> > property)
 {
     return(_properties.ContainsKey(PropertyNameGetter.Get(property)));
 }
 /// <summary>
 /// Records the given value for the given property from {TObject} and returns the builder to allow chaining.
 /// </summary>
 /// <typeparam name="TValue">The type of the property</typeparam>
 /// <param name="property">A lambda expression specifying the property to record a value for</param>
 /// <param name="value">The value to record</param>
 public TBuilder Set <TValue>(Expression <Func <TObject, TValue> > property, TValue value)
 {
     _properties[PropertyNameGetter.Get(property)] = value;
     return(this as TBuilder);
 }