DatabaseExpression
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Pattern.Interpreter
{
/**//// <summary>
/// 終端公式(TerminalExpression)分析與數據庫相關的
/// </summary>
public class DatabaseExpression : AbstractExpression
{
/**//// <summary>
/// 從輸入內容中取得要解釋的詞
/// </summary>
/// <param name="source">source</param>
/// <returns></returns>
public override string GetWord(string source)
{
MatchCollection mc;
Regex r = new Regex(@"\{(.*)\}");
mc = r.Matches(source);
return mc[0].Groups[1].Value;
}
/**//// <summary>
/// 獲取與數據庫相關的字典
/// </summary>
/// <returns></returns>
public override Dictionary<string, string> GetDictionary()
{
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("數據庫", "Sql");
return d;
}
}
}
ObjectExpression
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Pattern.Interpreter
{
/**//// <summary>
/// 終端公式(TerminalExpression)分析與對象相關的
/// </summary>
public class ObjectExpression : AbstractExpression
{
/**//// <summary>
/// 從輸入內容中取得要解釋的詞
/// </summary>
/// <param name="source">source</param>
/// <returns></returns>
public override string GetWord(string source)
{
MatchCollection mc;
Regex r = new Regex(@"\[(.*)\]");
mc = r.Matches(source);
return mc[0].Groups[1].Value;
}
/**//// <summary>
/// 獲取與對象相關的字典
/// </summary>
/// <returns></returns>
public override Dictionary<string, string> GetDictionary()
{
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("信息", "Message");
return d;
}
}
}