c# - Rewriting method declaration -
i'm iterating on methods in type , have rewrite aren't static. i'd have insert parameter either first or last parameter can't figure out how create parametersyntax
object
this have far
var methods = m in r.members.oftype<methoddeclarationsyntax>() !m.modifiers.contains(syntax.token(syntaxkind.statickeyword)) select new { orgmethoddecl = m, rewrittendecl = rewritemethoddeclaration(m,name)}; var rewrittentype = r; foreach(var m in methods){ rewrittentype = rewrittentype.replacenode(m.orgmethoddecl, m.rewrittendecl); }
and rewritemethoddeclaration
have issue
methoddeclarationsyntax rewritemethoddeclaration(methoddeclarationsyntax method, string name) { var p = syntax.parameter(); //type dynamic, name: name var parameters = method.parameterlist.addparameters(p); return method.withparameterlist(parameters); }
try this:
static methoddeclarationsyntax rewritemethoddeclaration(methoddeclarationsyntax method, string name) { var type = syntax.parsetypename("dynamic"); var identifier = syntax.identifier(string.format(" {0}", name)); var p = syntax.parameter( new syntaxlist<attributelistsyntax>(), new syntaxtokenlist(), type, identifier, null); var parameters = method.parameterlist.addparameters(p); return method.withparameterlist(parameters); }
Comments
Post a Comment