#region COPYRIGHT
//
//     THIS IS GENERATED BY TEMPLATE
//     
//     AUTHOR  :     ROYE
//     DATE       :     2010
//
//     COPYRIGHT (C) 2010, TIANXIAHOTEL TECHNOLOGIES CO., LTD. ALL RIGHTS RESERVED.
//
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace System.Text.Template
{
    public class TokenMatch
    {
        private readonly Dictionary<string, string> _SubMatches = new Dictionary<string, string>();
        private readonly string _TokenId;
        private readonly TemplateTokenType _TokenType;
        private readonly bool _RemoveEmptyLine;
        private readonly Match _Match;

        public TokenMatch(Regex regex, Match match, TemplateTokenType tokenType, bool removeEmptyLine, string tokenId)
        {
            _TokenType = tokenType;
            _TokenId = tokenId;
            _Match = match;
            _RemoveEmptyLine = removeEmptyLine;
            #region _SubMatches = { ... }

            Group group = null;
            foreach (string groupName in regex.GetGroupNames())
            {
                group = match.Groups[groupName];
                if (group.Success)
                {
                    _SubMatches[groupName] = group.Value;
                }
            }

            #endregion
        }

        public Match Match
        {
            get { return this._Match; }
        }

        public string Value
        {
            get { return this.Match.Value; }
        }

        public string TokenId
        {
            get { return _TokenId; }
        }

        public TemplateTokenType TokenType
        {
            get { return _TokenType; }
        }

        public Dictionary<string, string> SubMatches
        {
            get { return _SubMatches; }
        }

        public bool RemoveEmptyLine
        {
            get { return _RemoveEmptyLine; }
        }
    }
}
