Back to Harmony

Class GeneralExtensions

docs/api/HarmonyLib.GeneralExtensions.html

2.4.2.04.9 KB
Original Source

Class GeneralExtensions

General extensions for common cases

Inheritance

System.Object

GeneralExtensions

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
TypeNameDescription
System.Type[]parameters

The array of types

|

Returns
TypeDescription
System.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
TypeNameDescription
System.Reflection.MethodBasemember

The method/constructor

|

Returns
TypeDescription
System.String

A human readable description

|

FullDescription(Type)

A full description of a type

Declaration
public static string FullDescription(this Type type)
Parameters
TypeNameDescription
System.Typetype

The type

|

Returns
TypeDescription
System.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
TypeNameDescription
System.Collections.Generic.Dictionary\dictionary

The dictionary

| | System.String | key |

The key

|

Returns
TypeDescription
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
NameDescription
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
TypeNameDescription
System.Collections.Generic.Dictionary<S, T>dictionary

The dictionary

| | S | key |

The key

|

Returns
TypeDescription
T

The value for the key or the default value (of T) if that key does not exist

|

Type Parameters
NameDescription
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
TypeNameDescription
System.Typetype

The class/type to test

|

Returns
TypeDescription
System.Boolean

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
TypeNameDescription
System.Collections.Generic.IEnumerable<T>enumeration

The enumeration

| | System.Func<T, System.String> | converter |

An optional value converter (from T to string)

| | System.String | delimiter |

An optional delimiter

|

Returns
TypeDescription
System.String

The values joined into a string

|

Type Parameters
NameDescription
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
TypeNameDescription
System.Stringinput

The string to convert

| | System.String | quoteChar |

The string to convert

|

Returns
TypeDescription
System.String

A string literal surrounded by quoteChar

|

Types(ParameterInfo[])

A helper converting parameter infos to types

Declaration
public static Type[] Types(this ParameterInfo[] pinfo)
Parameters
TypeNameDescription
System.Reflection.ParameterInfo[]pinfo

The array of parameter infos

|

Returns
TypeDescription
System.Type[]

An array of types

|