alielie
2026-09-10 9ec80cafc23f5ee3278cacce3c9f86f4087b435a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using OpenTap.Addin;
using OpenTap.Addin.Entity;
using System;
using System.Text.RegularExpressions;
 
namespace AddInPlugin.Util
{
    public class MethodUtil
    {
        public static readonly MethodUtil Instance = new MethodUtil();
 
        private MethodUtil()
        {
        }
 
        public bool IsNullOrEmpty(object obj)
        {
            return string.IsNullOrEmpty(obj?.ToString());
        }
 
        public string Str(object obj)
        {
            return obj?.ToString();
        }
 
        public NumberData Abs(object obj)
        {
            if (NumberData.Support(obj))
            {
                var nd = new NumberData(obj.ToString());
                return new NumberData(Math.Abs(nd.value));
            }
            throw new ArgumentException($"Unsupported Type {obj.GetType()}");
        }
 
        public NumberData Sqrt(object obj)
        {
            if (NumberData.Support(obj))
            {
                var nd = new NumberData(obj.ToString());
                return new NumberData(Math.Sqrt(nd.value));
            }
            throw new ArgumentException($"Unsupported Type {obj.GetType()}");
        }
 
        public string[] Split(object data, object spliter)
        {
            return Regex.Split(data.ToString(), spliter.ToString());
        }
 
        public double Seconds(bool useless = true)
        {
            return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() / 1000d;
        }
 
        public string DateStr(string pattern = "yyyy-MM-dd HH:mm:ss")
        {
            return DateTime.Now.ToString(pattern);
        }
 
        public dynamic Ref(dynamic obj)
        {
            return obj;
        }
 
        public delegate NumberData Val(object target, RuntimeVariable result = null);
        public static Val GetValImpl()
        {
            return (object target, RuntimeVariable result) =>
            {
                try
                {
                    if (!(result is null)) result.__data___ = true;
                    return new NumberData(target.ToString());
                }
                catch (Exception ex)
                {
                    if (!(result is null)) result.__data___ = false;
                    return new NumberData(0);
                }
            };
        }
 
        public string Time(bool use24hours = false)
        {
            var now = DateTime.Now;
            return now.ToString(use24hours ? "HH:mm:ss" : "hh:mm:ss");
        }
 
        public DateTime Now()
        {
            return DateTime.Now;
        }
 
        public bool CompareString(object str1, object str2, object ignoreCase = null)
        {
            bool ignore = false;
            if (ignoreCase is bool ig)
            {
                ignore = ig;
            }
            else if (ignoreCase is RuntimeVariable rv)
            {
                ignore = rv.__data___;
            }
            return string.Equals(str1.ToString(), str2.ToString(),
                ignore ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
        }
    }
}