public static TypeNode GetTypeTemplateByName(params object[] definitions) { CompilationUnit template; string name = (string)definitions[0]; template = cuParts; for (int i = 0, n = ((Namespace)template.Nodes[0]).NestedNamespaces[0].Types[0].Members.Count; i < n; i++) { Member m = ((Namespace)template.Nodes[0]).NestedNamespaces[0].Types[0].Members[i]; if (!(m is TypeNode)) continue; TypeNode tn = (TypeNode)m; if (tn.Name.Name == name) { CS.Duplicator duplicator = new CS.Duplicator(module, null); duplicator.SkipBodies = false; TypeNode dupClass = duplicator.VisitTypeNode(tn); return dupClass; } } Debug.Assert(false); throw new ApplicationException("Type node '" + name + "' not found"); }
public static Property GetPropertyTemplate(string name) { int i, n = ((Namespace)cuProperties.Nodes[0]).NestedNamespaces[0].Types[0].Members.Count; for (i = 0; i < n; i++) { Property p = ((Namespace)cuProperties.Nodes[0]).NestedNamespaces[0].Types[0].Members[i] as Property; if (p != null && p.Name.Name == name) { CS.Duplicator duplicator = new CS.Duplicator(module, null); duplicator.SkipBodies = false; return duplicator.VisitProperty(p); } } throw new ArgumentException (string.Format("Property template '{0}' not found", name)); }
public static Statement GetStatementTemplate(string name) { for (int i = 0, n = ((Namespace)cuStatements.Nodes[0]).NestedNamespaces[0].Types[0].Members.Count; i < n; i++) { Method m = ((Namespace)cuStatements.Nodes[0]).NestedNamespaces[0].Types[0].Members[i] as Method; if (m != null && m.Name.Name == name) { CS.Duplicator duplicator = new CS.Duplicator(module, null); duplicator.SkipBodies = false; StatementList stmtList = duplicator.VisitStatementList(m.Body.Statements); return stmtList[0]; } } throw new ArgumentException(string.Format("Statement template '{0}' not found", name)); }
public static Expression GetExpressionTemplate(string name) { for (int i = 0, n = ((Namespace)cuExpressions.Nodes[0]).NestedNamespaces[0].Types[0].Members.Count; i < n; i++) { Field f = ((Namespace)cuExpressions.Nodes[0]).NestedNamespaces[0].Types[0].Members[i] as Field; if (f != null && f.Name.Name == name) { CS.Duplicator duplicator = new CS.Duplicator(module, null); duplicator.SkipBodies = false; Expression expr = duplicator.VisitExpression(f.Initializer); return expr; } } throw new ArgumentException(string.Format("Expression template '{0}' not found", name)); }