コード例 #1
0
 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());
       }
 }
コード例 #2
0
 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
ファイル: AstNodeExtensions.cs プロジェクト: TreeSeed/Tychaia
        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
ファイル: ExtensionMethods.cs プロジェクト: Netring/ILSpy
		/// <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
ファイル: QueryParsingUtils.cs プロジェクト: algida/ravendb
		public static string ToCSharp(this Expression expression)
		{
			var output = new CSharpOutputVisitor();
			expression.AcceptVisitor(output, null);
			return (output.Text);
		}
コード例 #6
0
 public static List<LocalVariableDeclaration> variables(this MethodDeclaration methodDeclaration)
 {
     var astVisitors = new AstVisitors();
     methodDeclaration.AcceptVisitor(astVisitors, null);
     return astVisitors.localVariableDeclarations;
 }
コード例 #7
0
 public static List<InvocationExpression> invocations(this MethodDeclaration methodDeclaration)
 {
     var astVisitors = new AstVisitors();
     methodDeclaration.AcceptVisitor(astVisitors, null);
     return astVisitors.invocationExpressions;
 }
コード例 #8
0
ファイル: Extensions.cs プロジェクト: hpsa/SharpDevelop
		/// <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;
		}