Использование нестатической функции в статической функции - C#
Формулировка задачи:
Имеется функция которая наследуется классом. Но в классе есть еще статические классы внутри которых статические функции. Как можно было бы в статической функции такую функцию пременить? Делегатом?
Решение задачи: «Использование нестатической функции в статической функции»
textual
Листинг программы
// Reference: Oxide.Ext.MySql using UnityEngine; using Rust; using Oxide.Game.Rust.Libraries; using Oxide.Core; using Oxide.Core.Plugins; using Oxide.Core.Libraries; using Oxide.Ext.MySql; //using Oxide.Ext.Rust.Libraries; using System; using System.Data; using System.Linq; using System.Text; using System.Collections.Generic; using System.Reflection; using UnityEngine; using UnityEngine.UI; // Reference: NLua namespace Oxide.Plugins { [Info("AccountSystem", "TheRyuzaki", "0.0.2")] public class AccountSystem : RustPlugin { // CFG Mysql public static string host = "localhost"; // HOST TO MYSQL public static string user = "root"; // USER TO MYSQL public static string pass = ""; // PASS TO MYSQL public static string basa = "rust"; // DATABASE NAME TO MYSQL // Timer SavingTimer; #region Main Functions and Events public Player_class Player; void Init() { Puts("в–€в–€в–€ в–€ в–€ в–€в–€в–€ в–€в–€в–€в–€ в–€в–€ в–€в–€ в–€ в–€ в–€в–€в–€в–€ в–€в–€в–€в–€ в–€ в–€ в–€в–€в–€"); Puts(" в–€ в–€ в–€ в–€ в–€ в–€ в–€в–€в–€ в–€ в–€ в–€в–€ в–€ в–€ в–€ в–€ в–€"); Puts(" в–€ в–€в–€в–€в–€ в–€в–€в–€ в–€в–€в–€в–€ в–€ в–€ в–€ в–€в–€ в–€в–€в–€в–€ в–€в–€ в–€"); Puts(" в–€ в–€ в–€ в–€ в–€ в–€ в–€ в–€ в–€ в–€в–€ в–€ в–€ в–€ в–€ в–€"); Puts(" в–€ в–€ в–€ в–€в–€в–€ в–€ в–€ в–€ в–€в–€в–€ в–€в–€в–€в–€ в–€ в–€ в–€ в–€ в–€в–€в–€"); Puts(" в–€"); Puts(" в•”в•ђв•ђв•—в•”в•— в•”в•—в•”в•ђв•ђв•—в•”в•ђв•ђв•ђв•ђв•—"); Puts(" в•љв•—в•”в•ќв•‘в•љв•ђв•ќв•‘в•љв•—в•”в•ќв•љв•ђв•—в•”в•ђв•ќ"); Puts(" в•‘в•‘ в•‘в•”в•— в•‘ в•‘в•‘ в•‘в•‘"); Puts(" в•‘в•‘ в•‘в•‘в•љв•—в•‘ в•‘в•‘ в•‘в•‘"); Puts(" в•”в•ќв•љв•—в•‘в•‘ в•‘в•‘в•”в•ќв•љв•— в•‘в•‘"); Puts(" в•љв•ђв•ђв•ќв•љв•ќ в•љв•ќв•љв•ђв•ђв•ќ в•љв•ќ"); Player = new Player_class(); List<BasePlayer> PlayerList = new List<BasePlayer>(); PlayerList = BasePlayer.activePlayerList; foreach (BasePlayer player in PlayerList) Player.LoadPlayer(player.userID.ToString(), player.displayName); SavingTimer = timer.Repeat(500, 0, () => Player.SavePlayers()); } void OnPluginUnloaded(Plugin pluginName) { SavingTimer.Destroy(); } void OnPlayerInit(BasePlayer player) { Player.LoadPlayer(player.userID.ToString(), player.displayName); } void OnPlayerDisconnected(BasePlayer player) { Player.UnloadPlayer(player.userID.ToString(), player.displayName); } #endregion #region Class Achivment public class Achivment_class : RustPlugin { } #endregion #region Class Player public class Player_class : RustPlugin { public Dictionary<string, Dictionary<string, Dictionary<string, string>>> Players = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>(); public Player_class() { Puts("Player System - Init();"); } public void LoadPlayer(string id, string username) { QueueWorkerThread(delegate { Dictionary<string, string> tmp_user = new Dictionary<string, string>(); GoNow: tmp_user = Mysql.getRow("SELECT * FROM `auth_accounts` WHERE `id` = '" + Mysql.filter(id) + "'"); if (tmp_user.Count < 1) { Puts("Detected new player <" + username + ">"); Mysql.query("INSERT INTO `auth_accounts` (`id`,`username`) VALUES ('" + id + "','" + Mysql.filter(username) + "')"); Mysql.query("INSERT INTO `characters_stat` (`id`) VALUES ('" + id + "')"); goto GoNow; } Players[id] = new Dictionary<string, Dictionary<string, string>>(); Players[id]["auth_accounts"] = new Dictionary<string, string>(); Players[id]["auth_accounts"] = tmp_user; Players[id]["auth_accounts"]["bantime"] = DateTime.Parse(Players[id]["auth_accounts"]["bantime"]).ToString("yyyy-MM-dd h:mm:ss"); Players[id]["auth_accounts"]["mutetime"] = DateTime.Parse(Players[id]["auth_accounts"]["mutetime"]).ToString("yyyy-MM-dd h:mm:ss"); Players[id]["auth_accounts"]["premium"] = DateTime.Parse(Players[id]["auth_accounts"]["premium"]).ToString("yyyy-MM-dd h:mm:ss"); Players[id]["auth_accounts"]["online"] = DateTime.Parse(Players[id]["auth_accounts"]["online"]).ToString("yyyy-MM-dd h:mm:ss"); tmp_user = Mysql.getRow("SELECT * FROM `characters_stat` WHERE `id` = '" + Mysql.filter(id) + "'"); Players[id]["characters_stat"] = new Dictionary<string, string>(); Players[id]["characters_stat"] = tmp_user; tmp_user = null; Puts("Player <" + username + "> loaded!"); }); } public void UnloadPlayer(string id, string username) { QueueWorkerThread(delegate { foreach (var r in Players[id]) { var col = ""; var val = ""; foreach (var r2 in r.Value) { if (col != "") col += ","; col += "`" + r2.Key + "`"; if (val != "") val += ","; val += (r2.Key == "online" && r.Key == "auth_accounts") ? "NOW()" : "'" + Mysql.filter(r2.Value) + "'"; } Mysql.query("REPLACE INTO `" + r.Key + "` (" + col + ") VALUES (" + val + ")"); col = null; val = null; } Players.Remove(id); Puts("Player <" + username + "> unloaded!"); }); } public void SavePlayers() { if (Players.Count > 0) { QueueWorkerThread(delegate { var s = ""; foreach (var r0 in Players) { foreach (var r in r0.Value) { var col = ""; var val = ""; foreach (var r2 in r.Value) { if (col != "") col += ","; col += "`" + r2.Key + "`"; if (val != "") val += ","; if (r2.Key == "online" && r.Key == "auth_accounts") val += "NOW()"; else val += "'" + Mysql.filter(r2.Value) + "'"; } if (s != "") s += " "; s += "REPLACE INTO `" + r.Key + "` (" + col + ") VALUES (" + val + ");"; } } Mysql.query(s); Puts(Players.Count.ToString() + " players saved."); s = null; GC.Collect(); }); } else Puts("Dont save playrs, online 0!"); } } #endregion #region Class MySql public class Mysql : RustPlugin { public static Connection connection; public static string filter(string str) { return str.Replace("'", "\'"); } public static void query(string str) { Sql s = Start(str); Interface.Oxide.GetLibrary<Oxide.Ext.MySql.Libraries.MySql>("MySql").Update(s, connection); } public static Dictionary<int, Dictionary<string, string>> getAll(string str) { var Result = new Dictionary<int, Dictionary<string, string>>(); var i = 0; Sql s = Start(str); IEnumerable<Dictionary<string, object>> Res = Interface.Oxide.GetLibrary<Oxide.Ext.MySql.Libraries.MySql>("MySql").Query(s, connection); foreach (var r in Res) { Result[i] = new Dictionary<string, string>(); foreach (var ex in r) if (!Result[i].ContainsKey(ex.Key)) Result[i][ex.Key] = ex.Value.ToString(); i++; } return Result; } public static Dictionary<string, string> getRow(string str) { Sql s = Start(str); IEnumerable<Dictionary<string, object>> Result = Interface.Oxide.GetLibrary<Oxide.Ext.MySql.Libraries.MySql>("MySql").Query(s, connection); Dictionary<string, string> r2 = new Dictionary<string, string>(); foreach (var r in Result) if (r2.Count < 1) foreach (var ex in r) { r2[ex.Key] = ex.Value.ToString(); } else break; return r2; } public static string getOne(string str) { Sql s = Start(str); IEnumerable<Dictionary<string, object>> Result = Interface.Oxide.GetLibrary<Oxide.Ext.MySql.Libraries.MySql>("MySql").Query(s, connection); string val = ""; foreach (var r in Result) { foreach (var ex in r) { val = ex.Value.ToString(); break; } break; } return val; } public static Sql Start(string str) { connection = Interface.Oxide.GetLibrary<Oxide.Ext.MySql.Libraries.MySql>("MySql").OpenDb(host, 3306, basa, user, pass); return Interface.Oxide.GetLibrary<Ext.MySql.Libraries.MySql>("MySql").NewSql().Append(str); } } #endregion } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д