Example #1
0
 public static void logDbgError(this string s, bool condition)         // for removing condition check if !TRACE
 {
     if (condition)
     {
         Log.msg(s, Log.MsgType.ERROR);
     }
 }
Example #2
0
        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); }
        }
Example #3
0
        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);
        }
Example #6
0
 public static void logDbg(this string s) => Log.msg(s, Log.MsgType.DBG);
Example #7
0
 public static bool logError(this string s)
 {
     Log.msg(s, Log.MsgType.ERROR);       return(true);
 }
Example #8
0
 public static bool logWarning(this string s)
 {
     Log.msg(s, Log.MsgType.WARNING); return(true);
 }
Example #9
0
 // 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);
 }
Example #10
0
 public static void appendToFile(this string s, string localPath)
 {
     try { File.AppendAllText(_formatFileName(localPath), s + Environment.NewLine); }
     catch (Exception e) { Log.msg(e); }
 }
Example #11
0
 public static void saveToFile(this string s, string localPath)
 {
     try { File.WriteAllText(_formatFileName(localPath), s); }
     catch (Exception e) { Log.msg(e); }
 }
Example #12
0
 public static void logError(this string s) => Log.msg(s, Log.MsgType.ERROR);
Example #13
0
 public static void logWarning(this string s) => Log.msg(s, Log.MsgType.WARNING);
Example #14
0
 public static void log(this string s) => Log.msg(s, Log.MsgType.INFO);
Example #15
0
 public static void logDbg(this List <string> strings, string msg = "") =>
 strings.ForEach(s => Log.msg(msg + s, Log.MsgType.DBG));