XMLMessage
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Builder
{
/**//// <summary>
/// XML方式操作Message
/// </summary>
public class XMLMessage
{
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public List<MessageModel> Get()
{
List<MessageModel> l = new List<MessageModel>();
l.Add(new MessageModel("XML方式獲取Message", DateTime.Now));
return l;
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public bool Insert(MessageModel mm)
{
// 代碼略
return true;
}
}
}
Operation
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace Pattern.Builder
{
/**//// <summary>
/// 操作(Product)
/// </summary>
public class Operation
{
private string _type;
private Dictionary<string, string> _dictionary;
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="type">產品類型</param>
public Operation(string type)
{
_dictionary = new Dictionary<string, string>();
this._type = type;
}
/**//// <summary>
/// 索引器
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string this[string key]
{
get { return _dictionary[key]; }
set { _dictionary[key] = value; }
}
/**//// <summary>
/// 獲得結果
/// </summary>
/// <returns></returns>
public string GetResult()
{
Assembly assembly = Assembly.Load("Pattern.Builder");
MethodInfo methodGet = assembly.GetType("Pattern.Builder." + _dictionary["get"].Split('|')[0]).GetMethod(_dictionary["get"].Split('|')[1]);
object objGet = methodGet.Invoke(assembly.CreateInstance("Pattern.Builder." + _dictionary["get"].Split('|')[0]), null);
List<MessageModel> m = (List<MessageModel>)objGet;
MethodInfo methodInsert = assembly.GetType("Pattern.Builder." + _dictionary["insert"].Split('|')[0]).GetMethod(_dictionary["insert"].Split('|')[1]);
object objInsert = methodInsert.Invoke(assembly.CreateInstance("Pattern.Builder." + _dictionary["insert"].Split('|')[0]), new object[] { new MessageModel(_dictionary["insert"].Split('|')[2], Convert.ToDateTime(_dictionary["insert"].Split('|')[3])) });
bool b = (bool)objInsert;
return "類型為" + this._type + "的執行結果:<br />" + b.ToString() + "<br />" + m[0].Message + " " + m[0].PublishTime.ToString() + "<br />";
}
}
}