static void SetPluginProperty <T>(BasePlugin plugin, string name, string target)
        {
            try
            {
                var field = plugin.GetType().GetField(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

                if (field != null && field.FieldType == typeof(T))
                {
                    var prop = typeof(BasePlugin).GetProperty(target);

                    prop.SetValue(plugin, field.GetValue(null), null);
                }
            }
            catch (Exception e)
            {
                Tools.WriteLine(e);
            }
        }
        public static BasePlugin ReloadPlugin(BasePlugin oldPlugin, bool saveState = true)
        {
            var fi = new FileInfo(oldPlugin.Path);

            BasePlugin newPlugin;

            if (fi.LastWriteTimeUtc > oldPlugin.PathTimestamp)
            {
                // plugin updated
                Tools.WriteLine("Plugin {0} is being updated from file.", oldPlugin.Name);
                newPlugin = LoadPluginFromPath(oldPlugin.Path);
            }
            else
            {
                Tools.WriteLine("Plugin {0} not updated, reinitializing.", oldPlugin.Name);
                newPlugin               = CreatePluginInstance(oldPlugin.GetType());
                newPlugin.Path          = oldPlugin.Path;
                newPlugin.PathTimestamp = oldPlugin.PathTimestamp;
                newPlugin.Name          = oldPlugin.Name;
            }

            if (newPlugin == null)
            {
                return(oldPlugin);
            }

            if (ReplacePlugin(oldPlugin, newPlugin, saveState))
            {
                return(newPlugin);
            }
            else if (oldPlugin.IsDisposed)
            {
                return(null);
            }

            return(oldPlugin);
        }