85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using Api.Framework.Tools;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Api.Framework.SDK
|
|
{
|
|
/// <summary>
|
|
/// 插件扩展类
|
|
/// </summary>
|
|
public static class PluginExtend
|
|
{
|
|
/// <summary>
|
|
/// 输出日志
|
|
/// </summary>
|
|
/// <param name="plugin"></param>
|
|
/// <param name="message">日志内容</param>
|
|
public static void OnLog(this Plugin plugin, string message)
|
|
{
|
|
EventClient.OnEvent(plugin, new Framework.Events.LogEvents("【" + plugin.Name + "】" + message));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读入配置
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="plugin"></param>
|
|
/// <returns></returns>
|
|
public static T ReadConfig<T>(this Plugin plugin)
|
|
{
|
|
var t = Util.Read<T>();
|
|
//System.Drawing.Color c = new System.Drawing.Color();
|
|
return t;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存配置
|
|
/// </summary>
|
|
/// <param name="plugin"></param>
|
|
/// <param name="obj">保存的对象</param>
|
|
public static void SaveConfig(this Plugin plugin, Object obj)
|
|
{
|
|
Util.Save(obj);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 反射获取某个对象属性的值
|
|
/// </summary>
|
|
/// <param name="obj">对象</param>
|
|
/// <param name="name">对象中的属性</param>
|
|
/// <returns></returns>
|
|
public static object FindPropertyValue(this Object obj, string name)
|
|
{
|
|
var _type = obj.GetType();
|
|
var _prot = _type.GetProperties();
|
|
foreach (System.Reflection.PropertyInfo p in _prot)
|
|
{
|
|
if (name == p.Name) return p.GetValue(obj);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 反射获取某个对象属性信息
|
|
/// </summary>
|
|
/// <param name="obj">对象</param>
|
|
/// <param name="name">对象中的属性</param>
|
|
/// <returns></returns>
|
|
public static System.Reflection.PropertyInfo FindPropertyInfo(this Object obj, string name)
|
|
{
|
|
var _type = obj.GetType();
|
|
var _prot = _type.GetProperties();
|
|
foreach (System.Reflection.PropertyInfo p in _prot)
|
|
{
|
|
if (name == p.Name) return p;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|
|
}
|