From e31cd24b05739a8d9e073960dfc2ff74ecd5c16b Mon Sep 17 00:00:00 2001 From: Vatsal Ambastha Date: Thu, 12 Mar 2020 19:35:53 +0530 Subject: [PATCH] feat: Add some List extension methods to make working with last elements easier --- ...anguageExtensions.cs => CSharpExtensions.cs} | 17 ++++++++++++++++- ...ensions.cs.meta => CSharpExtensions.cs.meta} | 0 2 files changed, 16 insertions(+), 1 deletion(-) rename Assets/Adrenak.Unex/Runtime/Scripts/Extensions/{LanguageExtensions.cs => CSharpExtensions.cs} (84%) rename Assets/Adrenak.Unex/Runtime/Scripts/Extensions/{LanguageExtensions.cs.meta => CSharpExtensions.cs.meta} (100%) diff --git a/Assets/Adrenak.Unex/Runtime/Scripts/Extensions/LanguageExtensions.cs b/Assets/Adrenak.Unex/Runtime/Scripts/Extensions/CSharpExtensions.cs similarity index 84% rename from Assets/Adrenak.Unex/Runtime/Scripts/Extensions/LanguageExtensions.cs rename to Assets/Adrenak.Unex/Runtime/Scripts/Extensions/CSharpExtensions.cs index e05008d..2a25201 100644 --- a/Assets/Adrenak.Unex/Runtime/Scripts/Extensions/LanguageExtensions.cs +++ b/Assets/Adrenak.Unex/Runtime/Scripts/Extensions/CSharpExtensions.cs @@ -129,5 +129,20 @@ public static bool IsNullOrEmpty(this List list) { public static bool IsNullOrEmpty(this T[] array) { return array == null || array.Length == 0; } - } + + public static T FromLast(this List list, int index) { + if (index >= list.Count) + throw new IndexOutOfRangeException(index + " is out of range"); + return list[list.Count - 1 - index]; + } + + public static T Last(this List list) { + return list.FromLast(0); + } + + public static void RemoveLast(this List list) { + var last = list.Last(); + list.Remove(last); + } + } } diff --git a/Assets/Adrenak.Unex/Runtime/Scripts/Extensions/LanguageExtensions.cs.meta b/Assets/Adrenak.Unex/Runtime/Scripts/Extensions/CSharpExtensions.cs.meta similarity index 100% rename from Assets/Adrenak.Unex/Runtime/Scripts/Extensions/LanguageExtensions.cs.meta rename to Assets/Adrenak.Unex/Runtime/Scripts/Extensions/CSharpExtensions.cs.meta