GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — EZCode/EZCode/EZHelp.cs at master · EZCodeLanguage/EZCode

Expand file tree

/

EZHelp.cs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
1235 lines (1199 loc) · 46 KB
/

EZHelp.cs

Copy path

File metadata and controls

1235 lines (1199 loc) · 46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using static EZCodeLanguage.Parser;
using static EZCodeLanguage.Interpreter;
using Timer = System.Timers.Timer;
using System.Data;
using System.Diagnostics;
using System.Timers;
using Microsoft.Win32;
using System.Reflection;
namespace EZCodeLanguage
{
public class EZHelp
{
public Interpreter Interpreter { get; set; }
public static string? Error = null;
public EZHelp(Interpreter interpreter)
{
Interpreter = interpreter;
}
public EZHelp() { Interpreter ??= Instance; }
// Main Package:
// include main
public void Print(string text)
{
text = Format(text.ToString());
Interpreter.Output = [.. Interpreter.Output, text.ToString()];
Console.WriteLine(text);
}
public void Clear()
{
Console.Clear();
Interpreter.Output = [];
}
public string Input()
{
string input = Interpreter.GetInput();
return input;
}
public string Format(object _text) => Format(_text, "'");
public string Format(object _text, object _char)
{
try
{
char c = char.Parse(_char.ToString());
string text = ObjectParse(_text.ToString(), "str", true).ToString();
string format = "";
char[] chars = text.ToCharArray();
bool open = true, backslash = false;
Range[] ranges = [];
int current = 0;
for (int i = 0, count = 0; i < chars.Length; i++, count++)
{
if (backslash)
{
int minus = 0;
backslash = false;
chars[i] =
chars[i] == '\\' ? '\\' :
chars[i] == 'n' ? '\n' :
chars[i] == 'r' ? '\r' :
chars[i] == 'c' ? ',' :
chars[i] == 'p' ? '.' :
chars[i] == '"' ? '\'' :
chars[i] == '\'' ? '"' :
chars[i] == '_' ? ' ' :
chars[i] == 'L' ? '{' :
chars[i] == 'R' ? '}' :
chars[i] == 'q' ? '?' :
chars[i] == 'a' ? '@' :
chars[i] == ';' ? ':' :
chars[i] == 's' ? ';' :
chars[i] == 'i' ? '!' :
chars[i];
if (chars[i] == 'E')
{
chars = chars.ToList().Where((x, y) => y != i).ToArray();
minus++;
}
count--;
i--;
chars = chars.ToList().Where((x, y) => y != i).ToArray();
i -= minus;
if (minus == 0)
format += chars[i];
continue;
}
else if (chars[i] == '\\')
{
backslash = true;
continue;
}
if (chars[i] == c)
{
chars = chars.ToList().Where((x, y) => y != i).ToArray();
open = !open;
count--;
if (open)
{
ranges[current].Count = count;
current++;
}
else
{
ranges = [.. ranges, new Range()];
ranges[current].Start = i;
count = 0;
}
i--;
continue;
}
format += chars[i];
}
for (int i = ranges.Length - 1; i >= 0; i--)
{
Range range = ranges[i];
string name = format.Substring(range.Start, range.Count),
instance_name = name;
if (name.Contains(':'))
{
instance_name = name.Split(':')[0].Trim();
}
if (Interpreter.Vars.Any(x => x.Name == instance_name))
{
format = format.Remove(range.Start, range.Count).Insert(range.Start, Interpreter.GetValue(name, DataType.GetType("str", Interpreter.Classes)).ToString());
}
else
{
Interpreter.parser.WatchIsFound([name], 0, out ExplicitWatch watch, out _);
object val = Interpreter.GetValue(watch != null ? watch.Runs : name, DataType.GetType("str", Interpreter.Classes));
format = format.Remove(range.Start, range.Count).Insert(range.Start, Interpreter.GetValue(val, new DataType(DataType.Types._string, null, "str")).ToString());
}
}
return format;
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
struct Range(int start, int end)
{
public int Start = start;
public int Count = end;
}
public string StringEmpty()
{
return string.Empty;
}
public object ObjectParse(object obj, object type) => ObjectParse(obj, type, false);
public object ObjectParse(object obj, object type, bool to_string, string arraySeperator = " ", bool returnNull = false)
{
try
{
if (obj.ToString().StartsWith("{") && obj.ToString().EndsWith("}"))
{
obj = obj.ToString().Substring(1, obj.ToString().Length - 2).Trim();
}
try
{
object o = obj;
do
{
object n = obj;
o = obj;
DataType data = DataType.GetType(type.ToString(), Interpreter.Classes);
if (Interpreter.Vars.Any(x => x.Name == n.ToString())) Interpreter.Vars.FirstOrDefault(x => x.Name == n.ToString()).DataType = data;
obj = Interpreter.GetValue(n, data, arraySeperator);
} while (obj != o);
}
catch when (returnNull) { return null; }
if (!to_string)
{
if (int.TryParse(obj.ToString(), out int i)) return i;
if (float.TryParse(obj.ToString(), out float f)) return f;
try { obj = Operate(obj.ToString(), false); return obj; } catch { }
try { obj = Evaluate(obj.ToString()); return obj; } catch { }
}
return obj;
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public bool Evaluate(string expression)
{
try
{
expression = expression.Replace("||", "or").Replace("&&", "and").Replace("&", "and").Replace("|", "or").Replace("!=", "<>");
DataTable table = new DataTable();
table.Columns.Add("expression", typeof(bool));
DataRow row = table.NewRow();
row["expression"] = DBNull.Value;
table.Rows.Add(row);
table.Columns["expression"].Expression = expression;
return (bool)row["expression"];
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public float Operate(string expression) => Operate(expression, true);
public float Operate(string expression, bool object_parse)
{
try
{
string[] parts = SplitWithDelimiters(object_parse ? (ObjectParse(expression, "str").ToString()) : expression, ['-', '+', '=', '*', '/', '%', '&', '|', '!', ' ']).Where(x => x != "" && x != " ").ToArray();
expression = "";
foreach (string e in parts)
{
expression += object_parse ? (ObjectParse(e, "float").ToString() + " ") : e + " ";
}
DataTable table = new DataTable();
table.Columns.Add("expression", typeof(string), expression);
DataRow row = table.NewRow();
table.Rows.Add(row);
return float.Parse((string)row["expression"]);
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public bool Expression(string expression)
{
char[] symbols = ['-', '+', '=', '*', '/', '%', '&', '|', '!', ' '];
string[] parts = SplitWithDelimiters(ObjectParse(expression, "str", true).ToString(), symbols).Where(x => x != "" && x != " ").ToArray();
bool allIsText = false;
for (int i = 0; i < parts.Length; i++)
{
string e = parts[i];
if ((new[] { "=", ">", "<", "=", "!=", "!", ">=", "<=" }).Any(x => x == e))
{
if (parts[i] == "!" && parts.Length > i + 1 && parts[i + 1] == "=")
{
parts[i] = "!=";
parts = parts.ToList().Where((item, index) => index != i + 1).ToArray();
}
if (!allIsText && !(float.TryParse(parts[i + 1], out _) || bool.TryParse(parts[i + 1], out _) || symbols.Any(x => x.ToString() == parts[i + 1])))
{
parts[i - 1] = $"'{StringParse(parts[i - 1])}'";
}
continue;
}
if ((new[] { "&", "|", "and", "not", "or", "&&", "||" }).Any(x => x == e))
{
allIsText = false;
continue;
}
bool isText = !(float.TryParse(e, out _) || bool.TryParse(e, out _) || symbols.Any(x => x.ToString() == e)) || allIsText;
if (isText) allIsText = true;
e = !isText ? StringParse(e) : $"'{StringParse(e)}'";
parts[i] = e;
}
expression = string.Join(" ", parts);
return Evaluate(expression.Trim());
}
public string StringExpression(string expression)
{
string[] parts = ObjectParse(expression, "str").ToString().Split(['+']).Where(x => x != "" && x != " ").Select(e => ObjectParse(e.Trim(), "str").ToString()).ToArray();
return string.Join("", parts);
}
public object? StringMod(object x, object y, object mod)
{
try
{
string m = mod.ToString(),
a = ObjectParse(x.ToString(), "str", true).ToString(),
b = ObjectParse(y.ToString(), "str", true).ToString();
switch (m)
{
case "+": return a + b;
case "-":
if (int.TryParse(b, out int res))
{
a = string.Join("", a.ToCharArray().Take(a.Length - res));
}
else
{
a = a.Replace(b, "");
}
return a;
case "*":
if (int.TryParse(b, out res))
{
string _a = a;
for (int i = 0; i < res; i++)
{
_a += a;
}
a = _a;
}
else
{
throw new Exception("Expcted number to multiply by");
}
return a;
case "/":
if (int.TryParse(b, out res))
{
int len = a.Length;
int newl = len / res;
a = string.Join("", a.ToCharArray().Take(a.Length - newl));
}
else
{
throw new Exception("Expcted number to divide by");
}
return a;
default: return null;
}
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public object Add(object x, object y)
{
try
{
float a = float.Parse(ObjectParse(x.ToString(), "float").ToString());
float b = float.Parse(ObjectParse(y.ToString(), "float").ToString());
return a + b;
}
catch
{
string a = ObjectParse(x.ToString(), "str").ToString();
string b = ObjectParse(y.ToString(), "str").ToString();
return a + b;
}
}
public object Subtract(object x, object y)
{
try
{
float a = float.Parse(ObjectParse(x.ToString(), "float").ToString());
float b = float.Parse(ObjectParse(y.ToString(), "float").ToString());
return a - b;
}
catch
{
string a = ObjectParse(x.ToString(), "str").ToString();
string b = ObjectParse(y.ToString(), "str").ToString();
if (int.TryParse(b, out int res))
{
a = string.Join("", a.ToCharArray().Take(a.Length - res));
}
else
{
a = a.Replace(b, "");
}
return a;
}
}
public object Multiply(object x, object y)
{
try
{
float a = float.Parse(ObjectParse(x.ToString(), "float").ToString());
float b = float.Parse(ObjectParse(y.ToString(), "float").ToString());
return a * b;
}
catch
{
string a = ObjectParse(x.ToString(), "str").ToString();
string b = ObjectParse(y.ToString(), "str").ToString();
if (int.TryParse(b, out int res))
{
string _a = a;
for (int i = 0; i < res; i++)
{
_a += a;
}
a = _a;
}
else
{
throw new Exception("Expcted number to multiply by");
}
return a;
}
}
public object Divide(object x, object y)
{
try
{
float a = float.Parse(ObjectParse(x.ToString(), "float").ToString());
float b = float.Parse(ObjectParse(y.ToString(), "float").ToString());
return a / b;
}
catch
{
string a = ObjectParse(x.ToString(), "str").ToString();
string b = ObjectParse(y.ToString(), "str").ToString();
if (int.TryParse(b, out int res))
{
int len = a.Length;
int newl = len / res;
a = string.Join("", a.ToCharArray().Take(a.Length - newl));
}
else
{
throw new Exception("Expcted number to divide by");
}
return a;
}
}
public bool Compare(object v1, object v2, object v3)
{
try
{
object[] values = [v1, v2, v3];
for (int i = 0; i < values.Length; i++)
{
values[i] = ObjectParse(values[i], "str");
}
string all = string.Join(" ", values.Select(x => x.ToString()));
try
{
return Expression(all);
}
catch
{
return false;
}
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public bool Compare(object v1, object v2)
{
return Compare(v1, v2, "");
}
public bool Compare(object v1)
{
return Compare(v1, "", "");
}
public string StringParse(object v) => ObjectParse(v, "str", true).ToString();
public string CharParse(object v) => ObjectParse(v, "char", true).ToString();
public bool BoolParse(object v) => bool.Parse(ObjectParse(v, "bool").ToString());
public float FloatParse(object v) => float.Parse(ObjectParse(v, "float").ToString());
public int IntParse(object v) => int.Parse(ObjectParse(v, "int").ToString());
public bool SameType(object a, object b)
{
if (a is Var va && b is Var vb)
{
if (va.Value is Class ca && vb.Value is Class cb)
{
return ca.Name == cb.Name;
}
else
{
return va.Value.GetType() == vb.Value.GetType();
}
}
else
{
return a.GetType() == b.GetType();
}
}
public int StringLength(object str) => StringParse(str).Length;
public void RunEZCode(string code)
{
try
{
code = ObjectParse(code, "str").ToString();
Parser parser = new Parser(string.Join(" ", code), "(instance running from inside file)");
parser.Parse();
Interpreter interpreter = new Interpreter(parser);
interpreter.Interperate();
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public bool IsType(object obj, object type)
{
try
{
type = StringParse(type);
if (obj.ToString().StartsWith("{") && obj.ToString().EndsWith("}"))
{
obj = obj.ToString().Substring(1, obj.ToString().Length - 2).Trim();
if (Interpreter.Vars.FirstOrDefault(x => x.Name == obj.ToString()) is Var var) obj = var;
else
{
throw new Exception($"Could not find variable \"{obj}\"");
}
if (!var.Value.ToString().StartsWith('#'))
{
throw new Exception($"For IsType method, use \"#varName\" with # sign");
}
else
{
if (var.Value is Class c)
{
c.Properties.First(x => x.Name.ToString() == "value").Value = var.Value.ToString().Remove(0, 1);
}
else
{
var.Value = var.Value.ToString().Remove(0, 1);
}
}
if (Interpreter.Vars.FirstOrDefault(x => x.Name == var.Value.ToString()) is Var v2) obj = v2;
else
{
throw new Exception($"Could not find variable \"{var.Value}\"");
}
}
if (obj is Var v)
{
if (v.Value is Class c)
{
return c.Name == type.ToString();
}
else if (v.DataType.ObjectClass is Class cl)
{
return cl.Name == type.ToString();
}
else
{
throw new Exception($"Variable \"{v.Name}\" is not defined");
}
}
else if (obj is Class c)
{
return c.Name == type.ToString();
}
else
{
throw new Exception($"Object \"{obj}\" is not a variable");
}
}
catch (Exception e)
{
Error = e.Message;
throw;
}
}
public Array ArrayGetArray(object _array)
{
if (_array.ToString().StartsWith("{") && _array.ToString().EndsWith("}"))
{
_array = _array.ToString().Substring(1, _array.ToString().Length - 2).Trim();
}
return Interpreter.Vars.FirstOrDefault(x => x.Name == _array.ToString())?.Value as Array;
}
public Array ArrayGenerateArray(object? _length)
{
object? lengthObj = Try(() => IntParse(_length));
if (lengthObj == null)
{
return Array.Empty<object>();
}
else
{
int length = int.Parse(lengthObj.ToString()!);
return Array.CreateInstance(typeof(object), length);
}
}
public object? ArrayGetIndex(object _array, object _index)
{
try
{
Array array = ArrayGetArray(_array);
int index = IntParse(_index);
return array.GetValue(index) ?? throw new Exception("Index outside bounds of array");
}
catch (Exception ex)
{
throw ThrowError(ex);
}
}
public void ArraySetIndex(object _array, object _index, object _value)
{
try
{
Array array = ArrayGetArray(_array);
int index = IntParse(_index);
object value = ObjectParse(_value, "str");
array.SetValue(value, index);
}
catch (Exception ex)
{
throw ThrowError(ex);
}
}
public int ArrayLength(object _array)
{
Array array = ArrayGetArray(_array);
return array.Length;
}
public int ArrayHashCodes(object _array)
{
Array array = ArrayGetArray(_array);
return array.GetHashCode();
}
public Array ArrayAppends(object _array, object _value)
{
object[] array = (object[])ArrayGetArray(_array);
object value = ObjectParse(_value, "str");
return array.Append(value).ToArray();
}
public Array ArrayPrepends(object _array, object _value)
{
object[] array = (object[])ArrayGetArray(_array);
object value = ObjectParse(_value, "str");
return array.Prepend(value).ToArray();
}
public object? ArrayFirst(object _array)
{
object[] array = (object[])ArrayGetArray(_array);
return array.First();
}
public object? ArrayLast(object _array)
{
object[] array = (object[])ArrayGetArray(_array);
return array.Last();
}
public Array ArraySplitString(object _text, object _splitter)
{
string text = StringParse(_text);
string splitter = Format(_splitter);
return text.Split(splitter);
}
public float MathFunc(object obj, object op)
{
try
{
obj = ObjectParse(obj, "str");
bool obj2_is_null = !obj.ToString().Contains(",");
object obj1 = obj;
if (!obj2_is_null) obj1 = obj.ToString().Split(",")[0];
object? obj2 = null;
obj1 = ObjectParse(obj1, "float");
if (!obj2_is_null) obj2 = ObjectParse(obj.ToString().Split(",")[1], "float");
op = StringParse(op);
if (!float.TryParse(obj1.ToString(), out float val1))
{
throw new Exception("Could not parse 'obj' to type 'float'");
}
if (!float.TryParse(!obj2_is_null ? obj2.ToString() : "", out float val2))
{
if (!obj2_is_null)
{
throw new Exception("Could not parse 'obj' to type 'float'");
}
}
string operation = string.Join("", op.ToString().ToLower().ToCharArray().Select((x, y) => { if (y == 0) return char.Parse(x.ToString().ToUpper()); else return x; }));
object[] parameters = [val1];
if (!obj2_is_null) parameters = [.. parameters, val2];
return float.Parse(InvokeMethod($"System.MathF.{operation}", parameters, this, out _).ToString());
}
catch (Exception ex)
{
Error = ex.Message;
throw;
}
}
public float Average(object obj)
{
object[] array = ObjectParse(obj, "str").ToString().Split(",");
float[] numbers = array.Select((x, y) => float.Parse(ObjectParse(array[y], "float").ToString())).ToArray();
float all = numbers.Sum();
return all / numbers.Length;
}
public float Pi() => MathF.PI;
public float E() => MathF.E;
public float Clamp(object _val, object _min, object _max)
{
float val = FloatParse(_val);
float min = FloatParse(_min);
float max = FloatParse(_max);
if (val < min) return min;
else if (val > max) return max;
else return val;
}
public float Power(object _val, object _pow)
{
float val = FloatParse(_val);
float pow = FloatParse(_pow);
return MathF.Pow(val, pow);
}
public int RandomNumber(object _min, object _max)
{
Random random = new Random();
int min = IntParse(_min);
int max = IntParse(_max);
return random.Next(min, max);
}
public int RoundToInt(object _num)
{
var num = FloatParse(_num);
return (int)Math.Round(num);
}
public string Trim(object text) => StringParse(text).Trim();
public string ToLower(object text) => StringParse(text).ToLower();
public string ToUpper(object text) => StringParse(text).ToUpper();
public string Replace(object text, object older, object newwer) => StringParse(text).Replace(StringParse(older), StringParse(newwer));
public string Substring(object text, object index, object length) => StringParse(text).Substring(IntParse(index), IntParse(length));
public bool StartsWith(object text, object val) => StringParse(text).StartsWith(StringParse(val));
public bool EndsWith(object text, object val) => StringParse(text).EndsWith(StringParse(val));
public bool RegexMatch(object _text, object _match)
{
string input = StringParse(_text);
string oattern = StringParse(_match);
var match = System.Text.RegularExpressions.Regex.Match(input, oattern);
return match.Success;
}
public static string FixDirPath(string path) => path.Replace("/", "\\").Replace(" : \\", ":\\");
public static string FixUrlPath(string path)
{
string replacedPath = path.Replace("\\", "/").Replace(" : ", ":");
return !(replacedPath.StartsWith("https://") || replacedPath.StartsWith("http://")) ? ("https://" + replacedPath) : replacedPath;
}
public string FileRead(object _path)
{
try
{
string path = StringParse(_path);
path = FixDirPath(path);
return File.ReadAllText(path);
}
catch (Exception e)
{
throw ThrowError(e);
}
}
public void FileWrite(object _path, object _text)
{
try
{
string path = StringParse(_path);
string text = StringParse(_text);
path = FixDirPath(path);
File.WriteAllText(path, text);
}
catch (Exception e)
{
throw ThrowError(e);
}
}
public void FileCreate(object _path)
{
try
{
string path = StringParse(_path);
path = FixDirPath(path);
File.Create(path).Close();
}
catch (Exception e)
{
throw ThrowError(e);
}
}
public void FileDelete(object _path)
{
try
{
string path = StringParse(_path);
path = FixDirPath(path);
File.Delete(path);
}
catch (Exception e)
{
throw ThrowError(e);
}
}
public void Exit() => Interpreter.hasexited = true;
public object? EnvironmentOS(object _property, object? _val1, object? _val2)
{
try
{
string? property = Try(() => StringParse(_property).ToLower(), () => throw ThrowError(new Exception("Error occured while getting property name from parameter")))?.ToString();
string? val1 = _val1 != null ? Try(() => StringParse(_val1))?.ToString() : null;
string? val2 = _val2 != null ? Try(() => StringParse(_val2))?.ToString() : null;
switch (property)
{
case "newline": return Environment.NewLine;
case "osversion": return Environment.OSVersion;
case "processpath": return Environment.ProcessPath;
case "is64bitprocess": return Environment.Is64BitProcess;
case "processid": return Environment.ProcessId;
case "commandline": return Environment.CommandLine;
case "currentdirectory": return Environment.CurrentDirectory;
case "currentmanagedthreadid": return Environment.CurrentManagedThreadId;
case "exitcode": return Environment.ExitCode;
case "hasshutdownstarted": return Environment.HasShutdownStarted;
case "is64bitoperatingsystem": return Environment.Is64BitOperatingSystem;
case "isprivilegedprocess": return Environment.IsPrivilegedProcess;
case "machinename": return Environment.MachineName;
case "processorcount": return Environment.ProcessorCount;
case "stacktrace": return Environment.StackTrace;
case "systemdirectory": return Environment.SystemDirectory;
case "systempagesize": return Environment.SystemPageSize;
case "tickcount": return Environment.TickCount;
case "tickcount64": return Environment.TickCount64;
case "userdomainname": return Environment.UserDomainName;
case "userinteractive": return Environment.UserInteractive;
case "username": return Environment.UserName;
case "version": return Environment.Version;
case "workingset": return Environment.WorkingSet;
case "getcommandlineargs": return Environment.GetCommandLineArgs();
case "getenvironmentvariables": return Environment.GetEnvironmentVariables();
case "getlogicaldrives": return Environment.GetLogicalDrives();
}
if (val1 != null)
{
Enum.TryParse(val1, out Environment.SpecialFolder fval1);
int.TryParse(val1, out int ival1);
switch (property)
{
case "exit": Environment.Exit(ival1); return null;
case "expandenvironmentvariables": return Environment.ExpandEnvironmentVariables(val1);
case "failfast": Environment.FailFast(val1); return null;
case "getenvironmentvariable": return Environment.GetEnvironmentVariable(val1);
case "getfolderpath": return Environment.GetFolderPath(fval1);
}
if (val2 != null)
{
switch (property)
{
case "equals": return Equals(val1, val2);
case "referenceequals": return ReferenceEquals(val1, val2);
case "setenvironmentvariable": Environment.SetEnvironmentVariable(val1, val2); return null;
}
}
}
throw new Exception($"The environment property '{property}' does not exist");
}
catch (Exception ex)
{
throw ThrowError(ex);
}
}
// EZHelp static functions:
public static T GetParameter<T>(object obj) => GetParameter<T>(obj, typeof(T).ToString());
public static T GetParameter<T>(object obj, string type)
{
EZHelp e = new EZHelp(Instance);
return (T)e.ObjectParse(obj, type);
}
public static object GetParameter(object obj, string type)
{
EZHelp e = new EZHelp(Instance);
return e.ObjectParse(obj, type);
}
public static Exception ThrowError(string message) => ThrowError(new Exception(message));
public static Exception ThrowError(Exception exception)
{
Error = exception.Message;
throw exception;
}
public static T? Try<T>(Func<object> function) => (T)Try(function);
public static object? Try(Func<object> function)
{
try
{
return function();
}
catch
{
return null;
}
}
public static T? Try<T>(Func<object> function, Func<object> handle) => (T)Try(function, handle);
public static object? Try(Func<object> function, Func<object> handle)
{
try
{
return function();
}
catch
{
return handle();
}
}
// Time Package:
// include time
public string DateTimeNow(object? _format)
{
try
{
string? format = Try(() => StringParse(_format))?.ToString();
if (format is not null)
{
return DateTime.Now.ToString(format);
}
else
{
return DateTime.Now.ToString();
}
}
catch (Exception ex)
{
throw ThrowError(ex);
}
}
public DateTime DateTimeExtract(object _t1)
{
try
{
if (_t1.ToString().StartsWith("{") && _t1.ToString().EndsWith("}"))
_t1 = _t1.ToString().Substring(1, _t1.ToString().Length - 2).Trim();
Var? vart1 = Interpreter?.Vars?.FirstOrDefault(x => x.Name == _t1.ToString());
Class? classt1 = (Class)Try(() => vart1?.Value as Class);
DateTime t1;
if (classt1 is not null)
{
t1 = new DateTime(
year: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "year").Value.ToString()),
month: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "month").Value.ToString()),
day: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "day").Value.ToString()),
hour: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "hour").Value.ToString()),
minute: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "minute").Value.ToString()),
second: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "second").Value.ToString()),
millisecond: int.Parse(classt1.Properties.FirstOrDefault(x => x.Name == "milisecond").Value.ToString())
);
}
else
{
if (vart1.Value is Var)
{
var interVar = (Var)vart1.Value;
var contains = Interpreter.Vars.Any(x => x.Name == interVar.Name);
if (!contains)
Interpreter.Vars = [.. Interpreter.Vars, interVar];
var result = DateTimeExtract(interVar.Name);
if (!contains)
Interpreter.Vars = Interpreter.Vars.Where(x => x.Name != interVar.Name).ToArray();
return result;
}
t1 = DateTime.Parse(vart1.Value.ToString());
}
return t1;
}
catch (Exception ex)
{
throw ThrowError(ex);
}
}
public int DateTimeCompare(object _t1, object _t2)
{
try
{
DateTime
t1 = DateTimeExtract(_t1),
t2 = DateTimeExtract(_t2);
return DateTime.Compare(t1, t2);
}
catch (Exception ex)
{
throw ThrowError(ex);
}
}
public object DateTimeParses(object _val)
{
try
View remainder of file in raw view
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.