} // The method this entry was originally constructed with (may be useful for transformations). // NOTE: 16 parameter max for Expression.GetDelegateType public RegistrationEntry(MethodInfo methodInfo) { MethodInfo = methodInfo; var paramExprs = methodInfo.GetParameters() .Select(pi => Expression.Parameter(pi.ParameterType, pi.Name)) .ToArray(); FunctionLambda = Expression.Lambda(Expression.Call(methodInfo, paramExprs), methodInfo.Name, paramExprs); // Need to make sure we have explicit FunctionAttribute = methodInfo.GetCustomAttribute <ExcelFunctionAttribute>(); if (FunctionAttribute == null) { FunctionAttribute = new ExcelFunctionAttribute { Name = methodInfo.Name } } ; else if (string.IsNullOrEmpty(FunctionAttribute.Name)) { FunctionAttribute.Name = methodInfo.Name; } ArgumentAttributes = new List <ExcelArgumentAttribute>(); foreach (var pi in methodInfo.GetParameters()) { var argAtt = pi.GetCustomAttribute <ExcelArgumentAttribute>(); if (argAtt == null) { argAtt = new ExcelArgumentAttribute { Name = pi.Name } } ; else if (string.IsNullOrEmpty(argAtt.Name)) { argAtt.Name = pi.Name; } ArgumentAttributes.Add(argAtt); } // Special check for final Params argument - transform to an ExcelParamsArgumentAttribute // NOTE: This won't work with a custom derived attribute... var lastParam = methodInfo.GetParameters().LastOrDefault(); if (lastParam != null && lastParam.GetCustomAttribute <ParamArrayAttribute>() != null) { var excelParamsAtt = new ExcelParamsArgumentAttribute(ArgumentAttributes.Last()); ArgumentAttributes[ArgumentAttributes.Count - 1] = excelParamsAtt; } }
// NOTE: 16 parameter max for Expression.GetDelegateType public RegistrationEntry(MethodInfo methodInfo) { MethodInfo = methodInfo; var paramExprs = methodInfo.GetParameters() .Select(pi => Expression.Parameter(pi.ParameterType, pi.Name)) .ToArray(); FunctionLambda = Expression.Lambda(Expression.Call(methodInfo, paramExprs), methodInfo.Name, paramExprs); // Need to make sure we have explicit FunctionAttribute = methodInfo.GetCustomAttribute<ExcelFunctionAttribute>(); if (FunctionAttribute == null) FunctionAttribute = new ExcelFunctionAttribute { Name = methodInfo.Name }; else if (string.IsNullOrEmpty(FunctionAttribute.Name)) FunctionAttribute.Name = methodInfo.Name; ArgumentAttributes = new List<ExcelArgumentAttribute>(); foreach (var pi in methodInfo.GetParameters()) { var argAtt = pi.GetCustomAttribute<ExcelArgumentAttribute>(); if (argAtt == null) argAtt = new ExcelArgumentAttribute { Name = pi.Name }; else if (string.IsNullOrEmpty(argAtt.Name)) argAtt.Name = pi.Name; ArgumentAttributes.Add(argAtt); } // Special check for final Params argument - transform to an ExcelParamsArgumentAttribute // NOTE: This won't work with a custom derived attribute... var lastParam = methodInfo.GetParameters().LastOrDefault(); if (lastParam != null && lastParam.GetCustomAttribute<ParamArrayAttribute>() != null) { var excelParamsAtt = new ExcelParamsArgumentAttribute(ArgumentAttributes.Last()); ArgumentAttributes[ArgumentAttributes.Count - 1] = excelParamsAtt; } }