Search Results for

    Show / Hide Table of Contents

    Class Extensions

    Collection of various extension methods.

    Inheritance
    System.Object
    Extensions
    Namespace: FlaxEngine.Utilities
    Assembly: FlaxEngine.CSharp.dll
    Syntax
    public static class Extensions : Object

    Methods

    AddRange<T>(ICollection<T>, IEnumerable<T>)

    Adds the elements of the specified collection to the end of the System.Collections.Generic.ICollection<>.

    Declaration
    public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> collection)
    Parameters
    System.Collections.Generic.ICollection<T> destination

    The System.Collections.Generic.ICollection<> to add items to.

    System.Collections.Generic.IEnumerable<T> collection

    The collection whose elements should be added to the end of the destination. It can contain elements that are null, if type T is a reference type.

    Type Parameters
    T

    The type of elements in the collection.

    Exceptions
    System.ArgumentNullException

    If destination or collection are null.

    Choose<T>(Random, T[])

    Chooses a random item.

    Declaration
    public static T Choose<T>(this Random random, params T[] collection)
    Parameters
    System.Random random

    An instance of System.Random.

    T[] collection

    Collection to choose item from.

    Returns
    T

    A random item from collection

    Type Parameters
    T

    The type of the elements of the input sequence.

    Exceptions
    System.ArgumentNullException

    If the random is null.

    System.ArgumentNullException

    If the collection is null.

    Choose<T>(Random, IList<T>)

    Chooses a random item from the collection.

    Declaration
    public static T Choose<T>(this Random random, IList<T> collection)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Collections.Generic.IList<T> collection

    Collection to choose item from.

    Returns
    T

    A random item from collection

    Type Parameters
    T

    The type of the elements of the input sequence.

    Exceptions
    System.ArgumentNullException

    If the random argument is null.

    System.ArgumentNullException

    If the collection is null.

    DeepClone<T>(T)

    Creates deep clone for a class if all members of this class are marked as serializable (uses Json serialization).

    Declaration
    public static T DeepClone<T>(this T instance)
        where T : new()
    Parameters
    T instance

    The input instance of an object.

    Returns
    T

    Returns new object of provided class.

    Type Parameters
    T

    The instance type of an object.

    EnqueueRange<T>(Queue<T>, IEnumerable<T>)

    Enqueues the elements of the specified collection to the System.Collections.Generic.Queue<>.

    Declaration
    public static void EnqueueRange<T>(this Queue<T> queue, IEnumerable<T> collection)
    Parameters
    System.Collections.Generic.Queue<T> queue

    The System.Collections.Generic.Queue<> to add items to.

    System.Collections.Generic.IEnumerable<T> collection

    The collection whose elements should be added to the queue. It can contain elements that are null, if type T is a reference type.

    Type Parameters
    T

    The type of elements in the collection.

    Exceptions
    System.ArgumentNullException

    If queue or collection are null.

    ForEach<T>(IEnumerable<T>, Action<T>)

    Performs the specified action on each element of the System.Collections.Generic.IEnumerable<>.

    Declaration
    public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
    Parameters
    System.Collections.Generic.IEnumerable<T> source

    The sequence of elements to execute the System.Collections.Generic.IEnumerable<>.

    System.Action<T> action

    The System.Action<> delegate to perform on each element of the System.Collections.Generic.IEnumerable<>1.

    Type Parameters
    T

    The type of the elements of the input sequence.

    Exceptions
    System.ArgumentException

    source or action is null.

    GetLines(String, Boolean)

    Splits string into lines

    Declaration
    public static string[] GetLines(this string str, bool removeEmptyLines = false)
    Parameters
    System.String str

    Text to split

    System.Boolean removeEmptyLines

    True if remove empty lines, otherwise keep them

    Returns
    System.String[]

    Array with all lines

    IsMultiline(String)

    Checks if the text is multiline.

    Declaration
    public static bool IsMultiline(this string str)
    Parameters
    System.String str

    Text to check.

    Returns
    System.Boolean

    True if text is a multiline, otherwise false.

    NextBool(Random, Single)

    Generates a random System.Boolean.

    Declaration
    public static bool NextBool(this Random random, float weight = 0.5F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single weight

    Normalized value that determines the chance to return true.

    Returns
    System.Boolean

    A System.Boolean thats either true or false.

    NextByte(Random, Byte)

    Generates a random System.Byte value up until an exclusive maximum.

    Declaration
    public static byte NextByte(this Random random, byte max = 0)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Byte max

    The maximum value. If it's zero, a maximum of 256 is used

    Returns
    System.Byte

    A random System.Byte between min and max.

    NextByte(Random, Byte, Byte)

    Generates a random System.Byte value between min and max.

    Declaration
    public static byte NextByte(this Random random, byte min, byte max)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Byte min

    The minimum value.

    System.Byte max

    The maximum value.

    Returns
    System.Byte

    A random System.Byte between min and max.

    NextColor(Random, Boolean)

    Generates a random Color.

    Declaration
    public static Color NextColor(this Random random, bool randomAlpha = false)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Boolean randomAlpha

    Randomize the alpha value.

    Returns
    Color

    A nice random Color.

    NextColorHSV(Random, Boolean)

    Generates a random ColorHSV.

    Declaration
    public static ColorHSV NextColorHSV(this Random random, bool randomAlpha = false)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Boolean randomAlpha

    Randomize the alpha value.

    Returns
    ColorHSV

    A nice random ColorHSV.

    NextDouble(Random, Double)

    Gets a random System.Double.

    Declaration
    public static double NextDouble(this Random random, double max = 1)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Double max

    The maximum value.

    Returns
    System.Double

    A random System.Double.

    NextDouble(Random, Double, Double)

    Gets a random System.Double.

    Declaration
    public static double NextDouble(this Random random, double min = 0, double max = 1)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Double min

    The minimum value.

    System.Double max

    The maximum value.

    Returns
    System.Double

    A random System.Double.

    NextEnum<TEnum>(Random)

    Returns a random value of the given enum.

    Declaration
    public static TEnum NextEnum<TEnum>(this Random random)
    Parameters
    System.Random random

    An instance of System.Random.

    Returns
    TEnum

    A random enum value.

    Type Parameters
    TEnum

    The enum to get the value from.

    NextFloat(Random, Single)

    Generates a random System.Single value between 0 and max.

    Declaration
    public static float NextFloat(this Random random, float max)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single max

    The maximum value.

    Returns
    System.Single

    A random System.Single between min and max.

    NextFloat(Random, Single, Single)

    Generates a random System.Single value between min and max.

    Declaration
    public static float NextFloat(this Random random, float min = 0F, float max = 1F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single min

    The minimum value.

    System.Single max

    The maximum value.

    Returns
    System.Single

    A random System.Single between min and max.

    NextQuaternion(Random, Boolean)

    Generates a random Quaternion.

    Declaration
    public static Quaternion NextQuaternion(this Random random, bool randomRoll = false)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Boolean randomRoll

    Should the roll value be randomized.

    Returns
    Quaternion

    A random Quaternion.

    NextUnitCircleVector2(Random, Single)

    Generates a random Vector2 point on a circle of a given radius.

    Declaration
    public static Vector2 NextUnitCircleVector2(this Random random, float radius = 1F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single radius

    Radius of circle. Default 1.0f./>.

    Returns
    Vector2

    A random Vector2.

    NextUnitVector2(Random, Single)

    Generates a random Vector2 point in a circle of a given radius.

    Declaration
    public static Vector2 NextUnitVector2(this Random random, float radius = 1F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single radius

    Radius of circle. Default 1.0f./>.

    Returns
    Vector2

    A random Vector2.

    NextUnitVector3(Random)

    Generates a uniformly distributed random unit length vector point on a unit sphere.

    Declaration
    public static Vector3 NextUnitVector3(this Random random)
    Parameters
    System.Random random

    An instance of System.Random.

    Returns
    Vector3

    A random Vector3.

    NextVector2(Random, Single, Single)

    Gets a random Vector2 with components in a given range.

    Declaration
    public static Vector2 NextVector2(this Random random, float min = 0F, float max = 1F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single min

    The minimum value.

    System.Single max

    The maximum value.

    Returns
    Vector2

    A random Vector2.

    NextVector3(Random, Single, Single)

    Gets a random Vector3 with components in a given range.

    Declaration
    public static Vector3 NextVector3(this Random random, float min = 0F, float max = 1F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single min

    The minimum value.

    System.Single max

    The maximum value.

    Returns
    Vector3

    A random Vector3.

    NextVector4(Random, Single, Single)

    Gets a random Vector4 with components in a given range.

    Declaration
    public static Vector4 NextVector4(this Random random, float min = 0F, float max = 1F)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Single min

    The minimum value.

    System.Single max

    The maximum value.

    Returns
    Vector4

    A random Vector4.

    PushRange<T>(Stack<T>, IEnumerable<T>)

    Pushes the elements of the specified collection to the System.Collections.Generic.Stack<>.

    Declaration
    public static void PushRange<T>(this Stack<T> stack, IEnumerable<T> collection)
    Parameters
    System.Collections.Generic.Stack<T> stack

    The System.Collections.Generic.Stack<> to add items to.

    System.Collections.Generic.IEnumerable<T> collection

    The collection whose elements should be pushed on to the stack. It can contain elements that are null, if type T is a reference type.

    Type Parameters
    T

    The type of elements in the collection.

    Exceptions
    System.ArgumentNullException

    If stack or collection are null.

    RawClone<T>(T)

    Creates raw clone for a structure using memory copy. Valid only for value types.

    Declaration
    public static T RawClone<T>(this T instance)
    Parameters
    T instance

    The input instance of an object.

    Returns
    T

    Returns new object of provided structure.

    Type Parameters
    T

    The instance type of an object.

    Shuffle<T>(Random, IList<T>)

    Shuffles the collection in place.

    Declaration
    public static void Shuffle<T>(this Random random, IList<T> collection)
    Parameters
    System.Random random

    An instance of System.Random.

    System.Collections.Generic.IList<T> collection

    Collection to shuffle.

    Type Parameters
    T

    The type of the elements of the input sequence.

    Exceptions
    System.ArgumentNullException

    If the random argument is null.

    System.ArgumentNullException

    If the random collection is null.

    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat