Click here to Skip to main content
15,886,799 members
Articles / Programming Languages / C#

C# CodeDOM parser

Rate me:
Please Sign up or sign in to vote.
4.56/5 (14 votes)
27 Jun 20026 min read 247.8K   4.3K   70  
This is a utility which parses C# source code and creates the CODEDOM tree of the code.
// TreeCreator.cs: Creates tree for TreeView control from CODEDOM tree
//
// Written by IZ for purposes of CS CODEDOM Parser, 2002
//(c) 2002 Ivan Zderadicka (ivan.zderadicka@seznam.cz)

namespace CodeTreeView
{
    using System;
    using IvanZ.CSParser;
    using System.CodeDom;
	using System.Windows.Forms;
    
    
    public class TreeCreator : IAnalyser
    {
        
		private TreeView tree;
		private TreeNode nsNode;
		private TreeNode typeNode;
		private TreeNode memberNode;
		
		public TreeCreator(TreeView tree)
		{
			this.tree=tree;
			
		}
		public virtual void AnalyzeCompUnit(CodeCompileUnit unit)
        {
        }
        
        public virtual void AnalyzeMember(CodeTypeMember member)
        {
			memberNode= new TreeNode("[M] "+member.Name);
			memberNode.Tag= member.UserData["Location"];
			typeNode.Nodes.Add(memberNode);
        }
        
        public virtual void AnalyzeNamespace(CodeNamespace ns)
        {
			nsNode=new TreeNode("[NS] "+ns.Name);
			nsNode.Tag= ns.UserData["Location"];
			tree.Nodes.Add(nsNode);
        }
        
        public virtual void AnalyzeParameters(CodeParameterDeclarationExpression parameter,bool isDeleg)
        {
			TreeNode parNode= new TreeNode("[P] "+parameter.Name);
			parNode.Tag= parameter.UserData["Location"];

			if (isDeleg)
				typeNode.Nodes.Add(parNode);
			else
				memberNode.Nodes.Add(parNode);
			
			
        }
        
        public virtual void AnalyzeType(CodeTypeDeclaration type)
        {
			typeNode= new TreeNode("[T] "+type.Name);
			typeNode.Tag= type.UserData["Location"];
			nsNode.Nodes.Add(typeNode);

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Czech Republic Czech Republic
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions