Click here to Skip to main content
15,892,674 members
Articles / Programming Languages / C#

CodeDom Assistant

Rate me:
Please Sign up or sign in to vote.
4.84/5 (26 votes)
21 Sep 20074 min read 139.3K   6.6K   82  
Generating CodeDom Code By Parsing C# or VB
// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
//     <version>$Revision: 1703 $</version>
// </file>

using System;
using System.Collections.Generic;

namespace NRefactoryASTGenerator.Ast
{
	[CustomImplementation, HasChildren]
	class CompilationUnit : AbstractNode {}
	
	[HasChildren]
	class NamespaceDeclaration : AbstractNode
	{
		string name;
		
		public NamespaceDeclaration(string name) {}
	}
	
	class TemplateDefinition : AttributedNode
	{
		[QuestionMarkDefault]
		string name;
		List<TypeReference> bases;
		
		public TemplateDefinition(string name, List<AttributeSection> attributes) : base(attributes) {}
	}
	
	class DelegateDeclaration : AttributedNode
	{
		[QuestionMarkDefault]
		string          name;
		TypeReference   returnType;
		List<ParameterDeclarationExpression> parameters;
		List<TemplateDefinition> templates;
		
		public DelegateDeclaration(Modifiers modifier, List<AttributeSection> attributes) : base(modifier, attributes) {}
	}
	
	enum ClassType { Class }
	
	[HasChildren]
	class TypeDeclaration : AttributedNode
	{
		// Children of Struct:    FieldDeclaration, MethodDeclaration, EventDeclaration, ConstructorDeclaration,
		//                        OperatorDeclaration, TypeDeclaration, IndexerDeclaration, PropertyDeclaration, in VB: DeclareDeclaration
		// Childrean of class:    children of struct, DestructorDeclaration
		// Children of Interface: MethodDeclaration, PropertyDeclaration, IndexerDeclaration, EventDeclaration, in VB: TypeDeclaration(Enum) too
		// Children of Enum:      FieldDeclaration
		string name;
		ClassType type;
		List<TypeReference> baseTypes;
		List<TemplateDefinition> templates;
		Location bodyStartLocation;
		
		public TypeDeclaration(Modifiers modifier, List<AttributeSection> attributes) : base(modifier, attributes) {}
	}
	
	[IncludeBoolProperty("IsAlias", "return !alias.IsNull;")]
	class Using : AbstractNode
	{
		[QuestionMarkDefault]
		string name;
		TypeReference alias;
		
		public Using(string name) {}
		public Using(string name, TypeReference alias) {}
	}
	
	[IncludeMember("public UsingDeclaration(string @namespace) : this(@namespace, null) {}")]
	[IncludeMember("public UsingDeclaration(string @namespace, TypeReference alias) {" +
	               " usings = new List<Using>(1);" +
	               " usings.Add(new Using(@namespace, alias)); " +
	               "}")]
	class UsingDeclaration : AbstractNode
	{
		List<Using> usings;
		
		public UsingDeclaration(List<Using> usings) {}
	}
	
	enum OptionType { None }
	
	class OptionDeclaration : AbstractNode
	{
		OptionType optionType;
		bool       optionValue;
		
		public OptionDeclaration(OptionType optionType, bool optionValue) {}
	}
}

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
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions