public static void logDbgError(this string s, bool condition) // for removing condition check if !TRACE { if (condition) { Log.msg(s, Log.MsgType.ERROR); } }
public static void saveToFile(this string s, string localPath) { string targetPath = formatFileName(localPath); Paths.ensurePath(targetPath); try { File.WriteAllText(targetPath, s); } catch (Exception e) { Log.msg(e); } }
public static T[] subArray <T>(this T[] array, int indexBegin, int indexEnd = -1) { try { int length = (indexEnd == -1? array.Length - 1: indexEnd) - indexBegin + 1; T[] newArray = new T[length]; Array.Copy(array, indexBegin, newArray, 0, length); return(newArray); } catch (Exception e) { Log.msg(e); return(null); } }
// if fields is empty we try to copy all fields public static void copyFieldsFrom <CT, CF>(this CT cmpTo, CF cmpFrom, params string[] fieldNames) where CT : Component where CF : Component { try { Type typeTo = cmpTo.GetType(), typeFrom = cmpFrom.GetType(); foreach (var fieldTo in fieldNames.Length == 0? typeTo.fields(): fieldNames.Select(name => typeTo.field(name))) { if (typeFrom.field(fieldTo.Name) is FieldInfo fieldFrom) { $"copyFieldsFrom: copying field {fieldTo.Name} from {cmpFrom} to {cmpTo}".logDbg(); fieldTo.SetValue(cmpTo, fieldFrom.GetValue(cmpFrom)); } } } catch (Exception e) { Log.msg(e); } }
public static T getArg <T>(this NotificationCenter.Notification n, int index) { T res = default; try { object arg = _getArg(n, index); if (arg != null) { res = (T)Convert.ChangeType(arg, typeof(T), CultureInfo.InvariantCulture); } } catch (Exception e) { Log.msg(e); } return(res); }
public static void logDbg(this string s) => Log.msg(s, Log.MsgType.DBG);
public static bool logError(this string s) { Log.msg(s, Log.MsgType.ERROR); return(true); }
public static bool logWarning(this string s) { Log.msg(s, Log.MsgType.WARNING); return(true); }
// can be used in conditions -> if (checkForError() && "write error to log".logError()) return; public static bool log(this string s) { Log.msg(s, Log.MsgType.INFO); return(true); }
public static void appendToFile(this string s, string localPath) { try { File.AppendAllText(_formatFileName(localPath), s + Environment.NewLine); } catch (Exception e) { Log.msg(e); } }
public static void saveToFile(this string s, string localPath) { try { File.WriteAllText(_formatFileName(localPath), s); } catch (Exception e) { Log.msg(e); } }
public static void logError(this string s) => Log.msg(s, Log.MsgType.ERROR);
public static void logWarning(this string s) => Log.msg(s, Log.MsgType.WARNING);
public static void log(this string s) => Log.msg(s, Log.MsgType.INFO);
public static void logDbg(this List <string> strings, string msg = "") => strings.ForEach(s => Log.msg(msg + s, Log.MsgType.DBG));