public abstract class BusinessSendAbstract
{
private object obj = "11";
private static Dictionary<string, object> pairs = new Dictionary<string, object>();
private void GetMethodAttribute<T>(T t)
{
bool isDoAction = pairs.ContainsKey(t.ToString());
lock (obj)
{
if (!isDoAction)
{
Type type = t.GetType();
foreach (MethodInfo mi in type.GetMethods())
{
ActionMethodAttribute[] mis = (ActionMethodAttribute[])mi.GetCustomAttributes(typeof(ActionMethodAttribute), false);
foreach (ActionMethodAttribute actionMethodAttribute in mis)
{
string actionName = actionMethodAttribute.ActionTypeName;
lock (obj)
pairs.Add(actionName, mi);
}
}
}
}
}
public object DoAction(string actionName, object[] obj = null)
{
object message = null;
GetMethodAttribute(this);
if (pairs.ContainsKey(actionName))
{
message = ((MethodInfo)pairs[actionName]).Invoke(this, obj).ToString();
}
else
{
message = string.Format("{0} 没有找见", actionName);
}
return message;
}
}
public class SendDomain : BusinessSendAbstract
{
[ActionMethod("SMS")]
public ResultInfo SendMobile(string phoneNumber, string warncontent)
{
return MobileMessage.SendMobileMag(phoneNumber, warncontent);
}
[ActionMethod("Email")]
public ResultInfo SendEmail(string toaddress, string sendcontent)
{
return new EmailSend().Send(toaddress, sendcontent);
}
[ActionMethod("WeChatAccount")]
public ResultInfo SendWeChat()
{
return new ResultInfo();
}
}
var u = new SendDomain().DoAction(sendType.ToString(), new object[] { sendData, mQSend.Templatevalue });