public ConfigFunctionInfo(string name, string description, string identifier, Delegate action, Func <string> message, params string[] paramNames) { Action = action; if (Action.Method.ReturnType != typeof(void)) // I couldn't find any non-generic Action object to use, best I got is a Delegate type. { throw new ArgumentException("Delegate must be without a return type, use of System.Action type required."); } Type[] generics = Action.GetType().GetGenericArguments(); if (generics.Length != paramNames.Length) { throw new ArgumentException("A differing amount of parameter names was given in comparison to the actions generic arguments. Lengths need to be identical."); } _parameters = new ConfigFunctionParam[generics.Length]; for (int i = 0; i < generics.Length; i++) { _parameters[i] = new ConfigFunctionParam(generics[i], paramNames[i]); } Name = name; Desc = description; Identifier = identifier; Message = message; }
public ConfigFunctionInfo(string name, string description, string identifier, Delegate action, Delegate message, params string[] paramNames) { Action = action; Message = message; if (Message.Method.ReturnType != typeof(string)) { throw new ArgumentException("Message delegate must have a string return type."); } Type[] generics = Action.GetType().GetGenericArguments(); if (Action.Method.ReturnType != typeof(void)) { generics = generics.ToList().GetRange(0, generics.Length - 1).ToArray(); // shut up; } if (generics.Length != paramNames.Length) { throw new ArgumentException("A differing amount of parameter names was given in comparison to the actions generic arguments. Lengths need to be identical."); } _parameters = new ConfigFunctionParam[generics.Length]; for (int i = 0; i < generics.Length; i++) { _parameters[i] = new ConfigFunctionParam(generics[i], paramNames[i]); } Name = name; Desc = description; Identifier = identifier; }