LanguageList.cs :  » Game » Balder » Fireball » Syntax » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » Balder 
Balder » Fireball » Syntax » LanguageList.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;

namespace Fireball.Syntax{
  /// <summary>
  /// Language list class
  /// </summary>
  public class LanguageList: IEnumerable
  {

    Dictionary<string,Language> _Languages=new Dictionary<string,Language>();


    /// <summary>
    /// Empty languagelist
    /// </summary>
        public LanguageList()
        {
           
        }


        /// <summary>
        /// Istance a new LanguageList from a directory and load files with specified extension
        /// </summary>
        /// <param name="directory">Directory where search files</param>
        /// <param name="ext">extension of syntax files</param>
        public LanguageList(string directory, string ext)
        {
            

            string[] files = Directory.GetFiles(directory, ext); //"*.syn");

            foreach (string file in files)
            {
                SyntaxLoader l = new SyntaxLoader();
                Language lng = l.Load(file);

                if (!_Languages.ContainsKey(lng.Name))
                    _Languages.Add(lng.Name, lng);
            }
        }



        public Language GetFromIndex(int index)
        {
            if (index >= 0 && index < _Languages.Count)
            {
                string[] keys = new string[_Languages.Keys.Count];

                _Languages.Keys.CopyTo(keys, 0);

                return _Languages[ keys[index]];
            }

            return null;
        }

        /// <summary>
        /// Get a language from it's name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Language GetLanguageFromName(string name)
        {
            if (!_Languages.ContainsKey(name))
                return null;

            return _Languages[name];
        }

        public void Add(Language lang)
        {
            if (!_Languages.ContainsKey(lang.Name))
                _Languages.Add(lang.Name, lang);
        }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public Language GetLanguageFromFile(string path)
    {
      string extension= System.IO.Path.GetExtension (path);

      foreach (Fireball.Syntax.Language lang in _Languages.Values)
      {
        foreach (Fireball.Syntax.FileType ft in lang.FileTypes)
        {
          if (extension.ToLower () == ft.Extension.ToLower ())
          {
            return lang;
          }
        }
      }
      return null;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
        public System.Collections.IEnumerator ListLanguages()
    {
      return _Languages.GetEnumerator() ;
    }

        #region IEnumerable Membri di

        public IEnumerator GetEnumerator()
        {
            return _Languages.GetEnumerator(); 
        }

        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.