/// <summary> /// Set the computed value to the <see cref="DateTime.Now"/> value when the request is made. /// </summary> /// <typeparam name="TPropertyConfiguration">The type of the property configuration.</typeparam> /// <param name="builder">The property configuration builder instance.</param> /// <returns>The property configuration builder instance.</returns> public static IPropertyConfigurationBuilder <DateTime, TPropertyConfiguration> DateTimeNow <TPropertyConfiguration>( this IComputedValueBuilder <DateTime, TPropertyConfiguration> builder) where TPropertyConfiguration : IPropertyConfiguration { builder.PropertyConfiguration.ValueComputationFunc.ValueComputationFunc = () => DateTime.Now; return(builder as IPropertyConfigurationBuilder <DateTime, TPropertyConfiguration>); }
/// <summary> /// Set the value of the property to a randomly generated GUID. /// </summary> /// <typeparam name="TPropertyConfiguration">The type of the property configuration.</typeparam> /// <param name="builder">The property configuration builder instance.</param> /// <returns>The property configuration builder instance.</returns> public static IPropertyConfigurationBuilder <Guid?, TPropertyConfiguration> RandomlyGeneratedGuid <TPropertyConfiguration>( this IComputedValueBuilder <Guid?, TPropertyConfiguration> builder) where TPropertyConfiguration : IInMemoryPropertyConfiguration { builder.PropertyConfiguration.ValueComputationFunc.ValueComputationFunc = () => Guid.NewGuid(); // Any property that has a computed value is by definition not read-only, so explicitly enforce this var propertyBuilder = builder as IPropertyConfigurationBuilder <Guid?, TPropertyConfiguration>; propertyBuilder.IsReadOnly(false); return(propertyBuilder); }
/// <summary> /// Set the value of the property to a global auto-incrementing integer. This is shared accross all properties that use this method. /// </summary> /// <typeparam name="TPropertyConfiguration">The type of the property configuration.</typeparam> /// <param name="builder">The property configuration builder instance.</param> /// <returns>The property configuration builder instance.</returns> public static IPropertyConfigurationBuilder <int, TPropertyConfiguration> AutoIncrementingInteger <TPropertyConfiguration>( this IComputedValueBuilder <int, TPropertyConfiguration> builder) where TPropertyConfiguration : IInMemoryPropertyConfiguration { builder.PropertyConfiguration.ValueComputationFunc.ValueComputationFunc = () => Interlocked.Increment(ref _globalPrimaryKey); // Any property that has a computed value is by definition not read-only, so explicitly enforce this var propertyBuilder = builder as IPropertyConfigurationBuilder <int, TPropertyConfiguration>; propertyBuilder.IsReadOnly(false); return(propertyBuilder); }
/// <summary> /// Set the computed value to the specified value when the request is made. /// </summary> /// <typeparam name="TProperty">The type of the property to set the value of.</typeparam> /// <typeparam name="TPropertyConfiguration">The type of the property configuration.</typeparam> /// <param name="builder">The property configuration builder instance.</param> /// <param name="computationFunc">The func to apply to the property to generate the value that will be persisted.</param> /// <returns>The property configuration builder instance.</returns> public static IPropertyConfigurationBuilder <TProperty, TPropertyConfiguration> Custom <TProperty, TPropertyConfiguration>( this IComputedValueBuilder <TProperty, TPropertyConfiguration> builder, Expression <Func <TProperty> > computationFunc) where TPropertyConfiguration : IPropertyConfiguration { builder.PropertyConfiguration.ValueComputationFunc.ValueComputationFunc = Expression.Lambda <Func <object> >(Expression.Convert(computationFunc.Body, typeof(object))); // Any property that has a computed value is by definition not read-only, so explicitly enforce this var propertyBuilder = builder as IPropertyConfigurationBuilder <TProperty, TPropertyConfiguration>; propertyBuilder.IsReadOnly(false); return(propertyBuilder); }