Browse documentation

Class GeneralExtensions

Namespace
HarmonyLib
Assembly
0Harmony.dll

General extensions for common cases

public static class GeneralExtensions
Inheritance
object
GeneralExtensions

Methods

Description(Type[])

Converts an array of types (for example methods arguments) into a human readable form

public static string Description(this Type[] parameters)

Parameters

parameters Type[]

The array of types

Returns

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

public static string FullDescription(this MethodBase member)

Parameters

member MethodBase

The method/constructor

Returns

string

A human readable description

FullDescription(Type)

A full description of a type

public static string FullDescription(this Type type)

Parameters

type Type

The type

Returns

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

public static T GetTypedValue<T>(this Dictionary<string, object> dictionary, string key)

Parameters

dictionary Dictionary<string, object>

The dictionary

key string

The key

Returns

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

T

The value type

GetValueSafe<S, T>(Dictionary<S, T>, S)

A helper to access a value via key from a dictionary

public static T GetValueSafe<S, T>(this Dictionary<S, T> dictionary, S key)

Parameters

dictionary Dictionary<S, T>

The dictionary

key S

The key

Returns

T

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

Type Parameters

S

The key type

T

The value type

HasHarmonyAttribute(Type)

Tests if a type has the HarmonyAttribute

public static bool HasHarmonyAttribute(this Type type)

Parameters

type Type

The class/type to test

Returns

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

public static string Join<T>(this IEnumerable<T> enumeration, Func<T, string> converter = null, string delimiter = ", ")

Parameters

enumeration IEnumerable<T>

The enumeration

converter Func<T, string>

An optional value converter (from T to string)

delimiter string

An optional delimiter

Returns

string

The values joined into a string

Type Parameters

T

The inner type of the enumeration

ToLiteral(string, string)

Escapes Unicode and ASCII non printable characters

public static string ToLiteral(this string input, string quoteChar = "\"")

Parameters

input string

The string to convert

quoteChar string

The string to convert

Returns

string

A string literal surrounded by quoteChar

Types(ParameterInfo[])

A helper converting parameter infos to types

public static Type[] Types(this ParameterInfo[] pinfo)

Parameters

pinfo ParameterInfo[]

The array of parameter infos

Returns

Type[]

An array of types

Harmony 3 preview

For the stable release, read the 2.x documentation.