public ExcelCommandRegistration(LambdaExpression commandLambda) { if (commandLambda == null) { throw new ArgumentNullException("commandLambda"); } CommandLambda = commandLambda; CommandAttribute = new ExcelCommandAttribute { Name = commandLambda.Name }; CustomAttributes = new List <object>(); }
} // List may not be null 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>(); }
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 }; } }