/// <summary> /// This is intended to be a short cut for setting named property values /// The expression will be inspected and the value will used by the property name /// WithNameCtorValue(() => someLocalVariable) will export the value under the name someLocalVariable /// </summary> /// <typeparam name="T">Type being exported</typeparam> /// <typeparam name="TValue">value type being used</typeparam> /// <param name="strategy">export strategy</param> /// <param name="valueExpression">value expression, the name of the parameter will be used as the parameter name</param> /// <returns>configuration object</returns> public static IFluentWithCtorConfiguration <T, TValue> WithNamedCtorValue <T, TValue>(this IFluentExportStrategyConfiguration <T> strategy, Expression <Func <TValue> > valueExpression) { var memberExpression = valueExpression.Body as MemberExpression; string exportName = null; if (memberExpression != null) { exportName = memberExpression.Member.Name; } if (exportName != null) { Func <TValue> func = valueExpression.Compile().Invoke; return(strategy.WithCtorParam(func).Named(memberExpression.Member.Name)); } throw new Exception("WithNamedCtorValue must be passed a Func that references a member"); }
/// <summary> /// Configure constructor parameter /// </summary> /// <param name="parameterType">parameter type</param> /// <returns></returns> public IFluentWithCtorConfiguration WithCtorParam(Type parameterType = null) { return(_strategy.WithCtorParam(parameterType)); }
/// <summary> /// Configure constructor parameter /// </summary> /// <typeparam name="TParam"></typeparam> /// <param name="paramFunc"></param> /// <returns></returns> public IFluentWithCtorConfiguration <TParam> WithCtorParam <TParam>(Func <TParam> paramFunc = null) { return(_strategy.WithCtorParam(paramFunc)); }