public static IReflectionTableBuilder AddReturnParameterAttributes <T>(this IReflectionTableBuilder builder, Expression <Action <T> > expression, IEnumerable <Attribute> attributes) { var method = Reflect.GetMethod <T>(expression); if (!method.DeclaringType.Equals(typeof(T))) { throw new ArgumentException($"The type '{typeof(T).FullName}' does not declare a method '{method.Name}'."); } return(builder.AddParameterAttributes(method.ReturnParameter, attributes)); }
private static IReflectionTableBuilder AddParameterAttributes(IReflectionTableBuilder builder, LambdaExpression expression) { MethodCallExpression methodCallExpression = expression.Body as MethodCallExpression; if (methodCallExpression == null) { throw new ArgumentException("Expression is not a single method call expression."); } MethodInfo targetMethod = (MethodInfo)Reflect.GetMemberInternal(methodCallExpression, true); var parameters = targetMethod.GetParameters(); for (int i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; var argCall = GetMethodCallExpression(methodCallExpression.Arguments[i]); if (argCall != null) { if (argCall.Method.IsGenericMethod && (s_decorateEnumerableMethodInfo.Equals(argCall.Method.GetGenericMethodDefinition()))) { Expression attrArg = argCall.Arguments[0]; var argLamb = Expression.Lambda <Func <IEnumerable <Attribute> > >(attrArg).Compile(); var attributes = argLamb(); builder.AddParameterAttributes(parameter, attributes); } else if (s_decorateParamsMethodInfo.Equals(argCall.Method.GetGenericMethodDefinition())) { Expression attrArg = argCall.Arguments[0]; var argLamb = Expression.Lambda <Func <Attribute[]> >(attrArg).Compile(); var attributes = argLamb(); builder.AddParameterAttributes(parameter, attributes); } } } return(builder); }
public static IReflectionTableBuilder AddReturnParameterAttributes(this IReflectionTableBuilder builder, Expression <Action> expression, IEnumerable <Attribute> attributes) { var method = Reflect.GetMethod(expression); return(builder.AddParameterAttributes(method.ReturnParameter, attributes)); }