InfinityExtensions.cs
v4.0
Is() and IsNot()
This will allow you to compare any value with another and return a true or false based on Is() or IsNot() -- if they are or are not the same value.
public static bool Is<T>(this T value, T compareValue)
public static bool IsNot<T>(this T value, T compareValue)
// Example
var userInputGatePhrase = "Open the Gate";
if (gate.passPhrase.Is(userInputGatePhrase))
OpenTheGate();
else
KillThePlayer(); // Harsh, but that's the rules of the game!TakeRandom(), TakeRandomIndex(), and TakeRandomAndIndex()
These extend a List<T> and return either an item from the list, the int index of an item from the list, or both!
public static T TakeRandom<T>(this List<T> list)
public static int TakeRandomIndex<T>(this List<T> list)
public static (T, int) TakeRandomAndIndex<T>(this List<T> list)
// Example
var newName = names.TakeRandom();
var randomName = names.TakeRandomAndIndex();
player.Name = newName.Item1;
player.NameIndex = newName.Item2;Shuffle()
Shuffles a list using the Fisher-Yates shuffle. Optionally providing a startIndex greater than 0, and only the values from that point on will be shuffled, retaining the order of the first group.
Reverse()
Reverses the order of a list. Optionally provide a startIndex, and only the items from that index on will be reversed.
AddDistinct()
If the list does not already contain the item to be added, it will be added, and true will be returned. If it already contains the item, then false will be returned.
RoundToDecimal
If the list does not already contain the item to be added, it will be added, and true will be returned. If it already contains the item, then false will be returned.
Last updated