jagregory / boolangstudio forked from olsonjeffery/boolangstudio

Boo language integration for Visual Studio 2008

This URL has Read+Write access

boolangstudio / Source / BooLangService / StringParsing / BracketPairType.cs
100644 39 lines (32 sloc) 1.102 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
 
namespace Boo.BooLangService.StringParsing
{
    public class BracketPairType
    {
        public static readonly BracketPairType Round = new BracketPairType('(', ')');
        public static readonly BracketPairType Square = new BracketPairType('[', ']');
        public static readonly BracketPairType Curly = new BracketPairType('{', '}');
 
        public static BracketPairType FromChar(char @char)
        {
            if (@char == '(' || @char == ')') return Round;
            if (@char == '[' || @char == ']') return Square;
            if (@char == '{' || @char == '}') return Curly;
 
            throw new ArgumentException("Invalid character, cannot resolve to bracket type.", "char");
        }
 
        private readonly char left;
        private readonly char right;
 
        private BracketPairType(char left, char right)
        {
            this.left = left;
            this.right = right;
        }
 
        public char Left
        {
            get { return left; }
        }
 
        public char Right
        {
            get { return right; }
        }
    }
}