Click here to Skip to main content
12,297,617 members (25,052 online)
Click here to Skip to main content

Stats

207.6K views
3.8K downloads
67 bookmarked
Posted

C# CodeDOM parser

, 27 Jun 2002
This is a utility which parses C# source code and creates the CODEDOM tree of the code.
CSParser
bin
Debug
Release
CodeTreeView
App.ico
bin
Debug
CodeTreeView.csproj.user
obj
Debug
temp
TempPE
cs-parser-modified.jay
cs-parser.jay
CSParser.csproj.user
CSParser.suo
jay
.cvsignore
ACKNOWLEDGEMENTS
ChangeLog
closure.o
conflict
CVS
Entries
Repository
Root
CVS
Entries
Entries.Log
Repository
Root
depend
error.o
jay.1
jay.exe
lalr.o
lr0.o
main.o
makefile
mkpar.o
NEW_FEATURES
NOTES
output.o
reader.o
README
README.jay
recover
CVS
Entries
Repository
Root
skeleton
symtab.o
verbose.o
warshall.o
NUnitTests
bin
Debug
Release
NUnitTests.csproj.user
obj
Debug
temp
TempPE
Release
temp
TempPE
TestFiles
obj
Debug
temp
TempPE
Release
temp
TempPE
testParser
bin
Debug
obj
Debug
temp
TempPE
testParser
App.ico
bin
Debug
Release
obj
Debug
temp
TempPE
Release
temp
TempPE
testParser.csproj.user
//SupportTypes.cs: Iterates CODEDOM tree and calls some analysys (defined by object 
//implementing IAnalyser interface
//
// Written by IZ for purposes of CS CODEDOM Parser, 2002
//(c) 2002 Ivan Zderadicka (ivan.zderadicka@seznam.cz)
using System;
using System.CodeDom;

namespace IvanZ.CSParser
{

	public interface IAnalyser
	{
		 void AnalyzeCompUnit(CodeCompileUnit unit);
		 void AnalyzeNamespace(CodeNamespace ns);
		 void AnalyzeType(CodeTypeDeclaration type);
		 void AnalyzeMember(CodeTypeMember member);
		 void AnalyzeParameters(CodeParameterDeclarationExpression parameter, bool isDeleg);

	}
	/// <summary>
	/// Summary description for TreeAnalyser.
	/// </summary>
	public class TreeAnalyzer
	{
		IAnalyser analyser;
		CodeCompileUnit unit;
		
		public TreeAnalyzer(IAnalyser analyser, CodeCompileUnit cu)
		{
			this.analyser=analyser;
			this.unit=cu;
		}

		public void DoAnalysis()
		{
			analyser.AnalyzeCompUnit(unit);
			for(int a=0; a<unit.Namespaces.Count; a++)
			{
				CodeNamespace ns= unit.Namespaces[a];
				analyser.AnalyzeNamespace(ns);
				for( int b=0; b<ns.Types.Count; b++)
				{
					CodeTypeDeclaration type= ns.Types[b];
					analyser.AnalyzeType(type);
					if (type is CodeTypeDelegate)
					{
						CodeTypeDelegate dlg= (CodeTypeDelegate) type;
						for(int i=0; i< dlg.Parameters.Count; i++)
							analyser.AnalyzeParameters(dlg.Parameters[i], true);
					}
					for (int c=0; c<type.Members.Count; c++)
					{
						CodeTypeMember member= type.Members[c];
						analyser.AnalyzeMember(member);
						CodeParameterDeclarationExpressionCollection pars=null;
						if (member is CodeMemberMethod)
							pars=((CodeMemberMethod)member).Parameters;
						else if (member is CodeMemberProperty)
							pars=((CodeMemberProperty)member).Parameters;
						if (pars!=null)
							for (int d=0; d<pars.Count; d++)
								analyser.AnalyzeParameters(pars[d], false);
					}
				}
			}
			
		}
	}
}

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

Share

About the Author

Ivan Zderadièka
Czech Republic Czech Republic
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 28 Jun 2002
Article Copyright 2002 by Ivan Zderadièka
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid