BadScript 2
Loading...
Searching...
No Matches
BadExtensions.cs
Go to the documentation of this file.
3
4namespace BadScript2.Utility;
5
9public static class BadExtensions
10{
16 public static bool IsCompletedSuccessfully(this Task task)
17 {
18 return task.Status == TaskStatus.RanToCompletion;
19 }
20
27 public static bool EndsWith(this string str, char c)
28 {
29 return str[str.Length - 1] == c;
30 }
31
38 public static bool StartsWith(this string str, char c)
39 {
40 return str[0] == c;
41 }
42
50 public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> e, int count)
51 {
52 Queue<T> q = new Queue<T>(count + 1);
53
54 foreach (T item in e)
55 {
56 if (q.Count == count + 1)
57 {
58 yield return q.Dequeue();
59 }
60
61 q.Enqueue(item);
62 }
63
64 if (q.Count == count + 1)
65 {
66 yield return q.Dequeue();
67 }
68 }
69
77 public static T GetProperty<T>(this BadObject obj, string propName)
78 {
79 BadObjectReference reference = obj.GetProperty(propName);
80
81 return reference.Dereference().Unwrap<T>();
82 }
83}
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadObject.cs:129
Implements the base functionality for a BadScript Reference.
Implements Extensions that aim to fix api differences between .Net Standard and .Net/....
static IEnumerable< T > SkipLast< T >(this IEnumerable< T > e, int count)
Skips the last n elements of an IEnumerable.
static bool EndsWith(this string str, char c)
Returns true if the string ends with the given character.
static T GetProperty< T >(this BadObject obj, string propName)
Returns a Property, unwrapped to the specified type, from the given object.
static bool IsCompletedSuccessfully(this Task task)
Returns true if the Task is completed successfully.
static bool StartsWith(this string str, char c)
Returns true if the string starts with the given character.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains Utility Functions and Classes.
Definition BadEnum.cs:5