Wanzyee Studio

Extension methods for linq operation. More...

Static Public Member Functions

static IEnumerable< T > ToAotEnumerable< T > (this IEnumerable< T > source)
 Convert to the sequence supports AOT, basically for a value type. More...
 
static string JoinText< T > (this IEnumerable< T > source, string separator="\n")
 Join the specified sequence to a string, basically for logging. More...
 
static bool IsExist (this object value)
 Determine if the specified object is existing, i.e., not equals null. More...
 
static IEnumerable< T > OfExist< T > (this IEnumerable< T > source)
 Filter elements which is not null. More...
 
static IEnumerable< string > OfText (this IEnumerable< string > source)
 Filter elements which is not null or empty string. More...
 
static IEnumerable< T > OfMatch< T > (this IEnumerable< T > source, string pattern, Func< T, string > selector=null, RegexOptions options=RegexOptions.ExplicitCapture)
 Filter elements which matches the specified regex pattern. More...
 
static Dictionary< T, U > ToDictionary< T, U > (this IEnumerable< IGrouping< T, U >> source)
 Create a Dictionary<TKey, TValue> from the sequence of IGrouping<TKey, TValue>. More...
 
static Dictionary< T, U > ToDictionary< T, U > (this IEnumerable< KeyValuePair< T, U >> source)
 Create a Dictionary<TKey, TValue> from the sequence of KeyValuePair<TKey, TValue>. More...
 
static Dictionary< T, U > KeysToDictionary< T, U > (this IEnumerable< T > source, Func< T, U > elementSelector)
 Create a Dictionary<TKey, TValue> from the sequence according to an element selector function. More...
 
static IEnumerable< T > OrderByRandom< T > (this IEnumerable< T > source)
 Sort the elements of a sequence in random order. More...
 
static T RandomElement< T > (this IEnumerable< T > source)
 Get the random element of a sequence, or a default value if no element. More...
 
static T RandomByWeight< T > (this IEnumerable<(T element, float weight)> source)
 Get the random element of a sequence by the specified weight, or a default value if no valid element. More...
 

Detailed Description

Extension methods for linq operation.

3

Member Function Documentation

static IEnumerable<T> ToAotEnumerable< T > ( this IEnumerable< T >  source)
static

Convert to the sequence supports AOT, basically for a value type.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence.
Returns
The sequence.
static string JoinText< T > ( this IEnumerable< T >  source,
string  separator = "\n" 
)
static

Join the specified sequence to a string, basically for logging.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence.
separatorSeparator.
Returns
The string.
static bool IsExist ( this object  value)
static

Determine if the specified object is existing, i.e., not equals null.

Parameters
valueValue.
Returns
true, if existing, false otherwise.
static IEnumerable<T> OfExist< T > ( this IEnumerable< T >  source)
static

Filter elements which is not null.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence.
Returns
The sequence.
static IEnumerable<string> OfText ( this IEnumerable< string >  source)
static

Filter elements which is not null or empty string.

Parameters
sourceThe source sequence.
Returns
The sequence.
static IEnumerable<T> OfMatch< T > ( this IEnumerable< T >  source,
string  pattern,
Func< T, string >  selector = null,
RegexOptions  options = RegexOptions.ExplicitCapture 
)
static

Filter elements which matches the specified regex pattern.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence.
patternThe regex pattern.
selectorThe transform function to get the text to match.
optionsThe regex options.
Returns
The sequence.
static Dictionary<T, U> ToDictionary< T, U > ( this IEnumerable< IGrouping< T, U >>  source)
static

Create a Dictionary<TKey, TValue> from the sequence of IGrouping<TKey, TValue>.

This uses the group key paired with the first element of the group.

Template Parameters
TThe key type.
UThe element type.
Parameters
sourceThe source sequence.
Returns
The dictionary.
static Dictionary<T, U> ToDictionary< T, U > ( this IEnumerable< KeyValuePair< T, U >>  source)
static

Create a Dictionary<TKey, TValue> from the sequence of KeyValuePair<TKey, TValue>.

Useful for arranging a dictionary, e.g., filtering, combining, or sorting.

Template Parameters
TThe key type.
UThe element type.
Parameters
sourceThe source sequence.
Returns
The dictionary.
static Dictionary<T, U> KeysToDictionary< T, U > ( this IEnumerable< T >  source,
Func< T, U >  elementSelector 
)
static

Create a Dictionary<TKey, TValue> from the sequence according to an element selector function.

Template Parameters
TThe key type.
UThe element type.
Parameters
sourceThe source sequence.
elementSelectorA transform function to produce an element value from each key.
Returns
The dictionary.
static IEnumerable<T> OrderByRandom< T > ( this IEnumerable< T >  source)
static

Sort the elements of a sequence in random order.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence.
Returns
The sequence.
static T RandomElement< T > ( this IEnumerable< T >  source)
static

Get the random element of a sequence, or a default value if no element.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence.
Returns
The random element.
static T RandomByWeight< T > ( this IEnumerable<(T element, float weight)>  source)
static

Get the random element of a sequence by the specified weight, or a default value if no valid element.

Template Parameters
TThe element type.
Parameters
sourceThe source sequence paired with the weight.
Returns
The random element.