void Macro(MacroOutput output, CodeConstruct sourceFileCode, string sourceFilePath, string defaultNamespace, int orderNo) { NamespaceDeclaration ns = output.CodeConstruct.CompilationUnit.PushChild(new NamespaceDeclaration(defaultNamespace)); ns.AddUsing("System"); ns.AddUsing("System.Reflection"); MakeGeneric(ns, sourceFileCode, "GenericAction"); }
void ExecuteMacro(MacroOutput output, CodeConstruct sourceFileCode, string sourceFilePath, string defaultNamespace, int orderNo) { NamespaceDeclaration ns = output.CodeConstruct.CompilationUnit.PushChild( new NamespaceDeclaration(sourceFileCode.CompilationUnit.Down().OfType <NamespaceDeclaration>().First().Name)); ns.AddUsing("System"); List <string> genericTypeNameList = new List <string>(); List <string> paramNameList = new List <string>(); for (int i = 1; i <= MAX_PARAMS; i++) { genericTypeNameList.Add("T" + i); paramNameList.Add("param" + i); } for (int paramCount = 1; paramCount <= MAX_PARAMS; paramCount++) { Func <string, int, bool> where = (name, index) => index < paramCount; IEnumerable <string> genericTypeNames = genericTypeNameList.Where(where); string[] paramNames = paramNameList.Where(where).ToArray(); CodeConstruct sourceFileCodeClone = sourceFileCode.Clone(); ns.AddChild(MakeGenericCopy(sourceFileCodeClone, "WeakAction", genericTypeNames, paramNames)); ns.AddChild(MakeGenericCopy(sourceFileCodeClone, "WeakFunc", genericTypeNames, paramNames)); } }