Iuvo Unity 0.5.1
This is library containing a variety of helper classes and extension methods for the Unity gane engine.
GitHub | Iuvo Unity Updates | Creator
Loading...
Searching...
No Matches
IuvoUnity.Extensions.GenericExtensions Class Reference

Provides generic extension methods for safe invocation, dictionary operations, and string formatting. More...

Static Public Member Functions

static void SafeInvoke< T > (this T obj, Action< T > action)
 Safely invokes the specified action if the object is not null.
static void AddOrUpdate< TKey, TValue > (this Dictionary< TKey, TValue > dictionary, TKey key, TValue value)
 Adds a key-value pair to the dictionary or updates the value if the key already exists.
static string ToSeparatedString (this IEnumerable< string > collection, string separator=", ")
 Joins a collection of strings into a single string, separated by the specified separator. Returns a single space if the collection is null.

Detailed Description

Provides generic extension methods for safe invocation, dictionary operations, and string formatting.

Member Function Documentation

◆ AddOrUpdate< TKey, TValue >()

void IuvoUnity.Extensions.GenericExtensions.AddOrUpdate< TKey, TValue > ( this Dictionary< TKey, TValue > dictionary,
TKey key,
TValue value )
static

Adds a key-value pair to the dictionary or updates the value if the key already exists.

Template Parameters
TKeyThe type of keys in the dictionary.
TValueThe type of values in the dictionary.
Parameters
dictionaryThe dictionary to update.
keyThe key to add or update.
valueThe value to set.
37 {
38 dictionary[key] = value;
39 }

◆ SafeInvoke< T >()

void IuvoUnity.Extensions.GenericExtensions.SafeInvoke< T > ( this T obj,
Action< T > action )
static

Safely invokes the specified action if the object is not null.

Template Parameters
TThe type of the object.
Parameters
objThe object to invoke the action on.
actionThe action to invoke.
21 {
22 if (obj != null)
23 {
24 action(obj);
25 }
26 }

◆ ToSeparatedString()

string IuvoUnity.Extensions.GenericExtensions.ToSeparatedString ( this IEnumerable< string > collection,
string separator = ", " )
static

Joins a collection of strings into a single string, separated by the specified separator. Returns a single space if the collection is null.

Parameters
collectionThe string collection to join.
separatorThe separator to use.
Returns
A separated string or a space if the collection is null.
49 {
50 return collection == null ? " " : string.Join(separator, collection);
51 }

The documentation for this class was generated from the following file: