public ExcelCommandRegistration(MethodInfo methodInfo) { CustomAttributes = new List<object>(); var paramExprs = methodInfo.GetParameters() .Select(pi => Expression.Parameter(pi.ParameterType, pi.Name)) .ToList(); CommandLambda = Expression.Lambda(Expression.Call(methodInfo, paramExprs), methodInfo.Name, paramExprs); var allMethodAttributes = methodInfo.GetCustomAttributes(true); foreach (var att in allMethodAttributes) { var cmdAtt = att as ExcelCommandAttribute; if (cmdAtt != null) { CommandAttribute = cmdAtt; // At least ensure that name is set - from the method if need be. if (string.IsNullOrEmpty(CommandAttribute.Name)) CommandAttribute.Name = methodInfo.Name; } else { CustomAttributes.Add(att); } } // Check that ExcelCommandAttribute has been set if (CommandAttribute == null) { CommandAttribute = new ExcelCommandAttribute { Name = methodInfo.Name }; } }
public ExcelCommandRegistration(LambdaExpression commandLambda) { if (commandLambda == null) throw new ArgumentNullException("commandLambda"); CommandLambda = commandLambda; CommandAttribute = new ExcelCommandAttribute { Name = commandLambda.Name }; CustomAttributes = new List<object>(); }
public ExcelCommandRegistration(LambdaExpression commandLambda, ExcelCommandAttribute commandAttribute) { if (commandLambda == null) throw new ArgumentNullException("commandLambda"); if (commandAttribute == null) throw new ArgumentNullException("commandAttribute"); CommandLambda = commandLambda; CommandAttribute = commandAttribute; // Create the lists - hope the rest is filled in right...? CustomAttributes = new List<object>(); }
// Fix up the ExplicitRegistration, since we _are_ now explicitly registering static void ClearExplicitRegistration(List <object> methodAttributes) { foreach (object attrib in methodAttributes) { if (attrib is ExcelFunctionAttribute funcAttrib) { funcAttrib.ExplicitRegistration = false; continue; } ExcelCommandAttribute cmdAttrib = attrib as ExcelCommandAttribute; if (cmdAttrib != null) { cmdAttrib.ExplicitRegistration = false; } } }