Class GeneralExtensions
General extensions for common cases
Inheritance
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public static class GeneralExtensions
Methods
Description(Type[])
Converts an array of types (for example methods arguments) into a human readable form
Declaration
public static string Description(this Type[] parameters)
Parameters
Type | Name | Description |
---|---|---|
Type[] | parameters | The array of types |
Returns
Type | Description |
---|---|
string | A human readable description including brackets |
FullDescription(MethodBase)
A a full description of a method or a constructor without assembly details but with generics
Declaration
public static string FullDescription(this MethodBase member)
Parameters
Type | Name | Description |
---|---|---|
MethodBase | member | The method/constructor |
Returns
Type | Description |
---|---|
string | A human readable description |
FullDescription(Type)
A full description of a type
Declaration
public static string FullDescription(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type |
Returns
Type | Description |
---|---|
string | A human readable description |
GetTypedValue<T>(Dictionary<string, object>, string)
A helper to access a value via key from a dictionary with extra casting
Declaration
public static T GetTypedValue<T>(this Dictionary<string, object> dictionary, string key)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<string, object> | dictionary | The dictionary |
string | key | The key |
Returns
Type | Description |
---|---|
T | The value for the key or the default value (of T) if that key does not exist or cannot be cast to T |
Type Parameters
Name | Description |
---|---|
T | The value type |
GetValueSafe<S, T>(Dictionary<S, T>, S)
A helper to access a value via key from a dictionary
Declaration
public static T GetValueSafe<S, T>(this Dictionary<S, T> dictionary, S key)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<S, T> | dictionary | The dictionary |
S | key | The key |
Returns
Type | Description |
---|---|
T | The value for the key or the default value (of T) if that key does not exist |
Type Parameters
Name | Description |
---|---|
S | The key type |
T | The value type |
HasHarmonyAttribute(Type)
Tests if a type has the HarmonyAttribute
Declaration
public static bool HasHarmonyAttribute(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The class/type to test |
Returns
Type | Description |
---|---|
bool | True if the type has the HarmonyAttribute |
Join<T>(IEnumerable<T>, Func<T, string>, string)
Joins an enumeration with a value converter and a delimiter to a string
Declaration
public static string Join<T>(this IEnumerable<T> enumeration, Func<T, string> converter = null, string delimiter = ", ")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumeration | The enumeration |
Func<T, string> | converter | An optional value converter (from T to string) |
string | delimiter | An optional delimiter |
Returns
Type | Description |
---|---|
string | The values joined into a string |
Type Parameters
Name | Description |
---|---|
T | The inner type of the enumeration |
ToLiteral(string, string)
Escapes Unicode and ASCII non printable characters
Declaration
public static string ToLiteral(this string input, string quoteChar = "\"")
Parameters
Type | Name | Description |
---|---|---|
string | input | The string to convert |
string | quoteChar | The string to convert |
Returns
Type | Description |
---|---|
string | A string literal surrounded by |
Types(ParameterInfo[])
A helper converting parameter infos to types
Declaration
public static Type[] Types(this ParameterInfo[] pinfo)
Parameters
Type | Name | Description |
---|---|---|
ParameterInfo[] | pinfo | The array of parameter infos |
Returns
Type | Description |
---|---|
Type[] | An array of types |