Click here to Skip to main content
15,860,844 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 136.5K   6.6K   82  
Generating CodeDom Code By Parsing C# or VB
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Xml;
using System.IO;

namespace ScintillaNet
{
	public class SnippetList : KeyedCollection<string,Snippet>
	{
		SnippetManager _manager;
		internal SnippetList(SnippetManager manager)
		{
			if (_manager != null)
			{
				_manager = manager;
			}
		}


		protected override string GetKeyForItem(Snippet item)
		{
			return item.Shortcut;
		}

		public Snippet Add(string shortcut, string code)
		{
			return Add(shortcut, code, _manager.DefaultDelimeter);
		}

		public Snippet Add(string shortcut, string code, bool isSurroundsWith)
		{
			return Add(shortcut, code, _manager.DefaultDelimeter, isSurroundsWith);
		}

		public Snippet Add(string shortcut, string code, char delimeter)
		{
			return Add(shortcut, code, delimeter, false);
		}

		public Snippet Add(string shortcut, string code, char delimeter, bool isSurroundsWith)
		{
			Snippet s = new Snippet(shortcut, code, delimeter, isSurroundsWith);
			Add(s);
			return s;
		}

		public bool TryGetValue(string key, out Snippet snippet)
		{
			if(this.Contains(key))
			{
				snippet = this[key];
				return true;
			}
			else
			{
				snippet = null;
				return false;
			}
		}

		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();
			foreach (Snippet s in this.Items)
				sb.Append(s.Shortcut).Append(" ");

			if (sb.Length > 0)
				sb.Remove(sb.Length - 1, 1);
			return sb.ToString();
		}

		public void Sort()
		{
			
			Snippet[] a = new Snippet[Count];
			CopyTo(a, 0);
			Array.Sort<Snippet>(a);

			Clear();
			AddRange(a);
		}

		public void AddRange(IEnumerable<Snippet> snippets)
		{
			foreach (Snippet s in snippets)
				Add(s);
		}
	}
}

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