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) ;
     }
 }
示例#3
0
        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();
        }
示例#4
0
		/// <summary>
		/// Gets whether the type is an open type (contains type parameters).
		/// </summary>
		/// <example>
		/// <code>
		/// class X&lt;T&gt; {
		///   List&lt;T&gt; open;
		///   X&lt;X&lt;T[]&gt;&gt; open;
		///   X&lt;string&gt; 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;
		}
示例#5
0
		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;
 }
示例#8
0
		/// <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;
		}