public static CSharpMethodBodyStatistics GetBodyStatistics(this MethodDeclaration declaration) { using (var writer = new StringWriter()) { var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateAllman()); declaration.AcceptVisitor(visitor); var bodyAsString = writer.ToString(); return new CSharpMethodBodyStatistics( bodyAsString.Split(new[] {Environment.NewLine}, StringSplitOptions.None).Length, bodyAsString.Length, bodyAsString.GetHashCode()); } }
public static string csharpCode(this INode iNode) { try { var outputVisitor = new CSharpOutputVisitor(); iNode.AcceptVisitor(outputVisitor, null); return outputVisitor.Text; } catch (Exception ex) { ex.log("in CSharpSourceCode_ExtensionMethods.csharpCode"); return "error creating source code for iNode. Error message was: ".format(ex.Message) ; } }
public static string GetTrackedText(this AstNode node, CSharpFormattingOptions formattingOptions = null) { if (node.IsNull) { return string.Empty; } var stringWriter = new StringWriter(); var wrapper = new TrackingOutputFormatter(stringWriter); wrapper.IndentationString = " "; node.AcceptVisitor(new CSharpOutputVisitor(wrapper, formattingOptions ?? FormattingOptionsFactory.CreateMono())); return stringWriter.ToString(); }
/// <summary> /// Gets whether the type is an open type (contains type parameters). /// </summary> /// <example> /// <code> /// class X<T> { /// List<T> open; /// X<X<T[]>> open; /// X<string> closed; /// int closed; /// } /// </code> /// </example> public static bool IsOpen(this IType type) { if (type == null) throw new ArgumentNullException("type"); TypeClassificationVisitor v = new TypeClassificationVisitor(); type.AcceptVisitor(v); return v.isOpen; }
public static string ToCSharp(this Expression expression) { var output = new CSharpOutputVisitor(); expression.AcceptVisitor(output, null); return (output.Text); }
public static List<LocalVariableDeclaration> variables(this MethodDeclaration methodDeclaration) { var astVisitors = new AstVisitors(); methodDeclaration.AcceptVisitor(astVisitors, null); return astVisitors.localVariableDeclarations; }
public static List<InvocationExpression> invocations(this MethodDeclaration methodDeclaration) { var astVisitors = new AstVisitors(); methodDeclaration.AcceptVisitor(astVisitors, null); return astVisitors.invocationExpressions; }
/// <summary> /// Finds TypeDeclarations in AST tree. /// </summary> public static ReadOnlyCollection<TypeDeclaration> FindTypeDeclarations(this INode astTree) { var findVisitor = new FindTypeDeclarationsVisitor(); astTree.AcceptVisitor(findVisitor, null); return findVisitor.Declarations; }