Table of Contents

Class ObjectExtensions

Namespace
AngleSharp.Common
Assembly
AngleSharp.dll

Some methods for working with bare objects.

public static class ObjectExtensions
Inheritance
ObjectExtensions
Inherited Members

Methods

Concat<T>(IEnumerable<T>, T)

Returns the concatenation of the provided enumerable with the specified element. The item is added to the beginning.

public static IEnumerable<T> Concat<T>(this IEnumerable<T> items, T element)

Parameters

items IEnumerable<T>

The items.

element T

The item to concat.

Returns

IEnumerable<T>

The new enumerable.

Type Parameters

T

The type of the enumeration.

Constraint(double, double, double)

Constraints the given value between the min and max values.

public static double Constraint(this double value, double min, double max)

Parameters

value double

The value to limit.

min double

The lower boundary.

max double

The upper boundary.

Returns

double

The value in the [min, max] range.

Except<T>(IEnumerable<T>, T)

Returns the removal of the specified element from the provided enumerable.

public static IEnumerable<T> Except<T>(this IEnumerable<T> items, T element)

Parameters

items IEnumerable<T>

The items.

element T

The item to remove.

Returns

IEnumerable<T>

The new enumerable.

Type Parameters

T

The type of the enumeration.

GetItemByIndex<T>(IEnumerable<T>, int)

Gets an item from the enumerable by its index. Throws an exception if the provided index is invalid.

public static T GetItemByIndex<T>(this IEnumerable<T> items, int index)

Parameters

items IEnumerable<T>

The items to iterate over.

index int

The index to look for.

Returns

T

The item at the specified index.

Type Parameters

T

The type of enumerable.

GetMessage<T>(T)

Retrieves a string describing the error of a given error code.

public static string GetMessage<T>(this T code) where T : Enum

Parameters

code T

A specific error code.

Returns

string

The description of the error.

Type Parameters

T

GetOrDefault<T, U>(IDictionary<T, U>, T, U?)

Gets the value of the given key, otherwise the provided default value.

public static U? GetOrDefault<T, U>(this IDictionary<T, U> values, T key, U? defaultValue) where T : notnull where U : notnull

Parameters

values IDictionary<T, U>

The dictionary for the lookup.

key T

The key to look for.

defaultValue U

The provided fallback value.

Returns

U

The value or the provided fallback.

Type Parameters

T

The type of the keys.

U

The type of the value.

ToDictionary(object?)

Transforms the values of the object into a dictionary of strings.

public static Dictionary<string, string> ToDictionary(this object? values)

Parameters

values object

The object instance to convert.

Returns

Dictionary<string, string>

A dictionary mapping field names to values.

TryGet(IDictionary<string, object>, string)

Tries to obtain the given key, otherwise returns null.

public static object? TryGet(this IDictionary<string, object> values, string key)

Parameters

values IDictionary<string, object>

The dictionary for the lookup.

key string

The key to look for.

Returns

object

An object instance or null.

TryGet<T>(IDictionary<string, object>, string)

Tries to obtain the given key, otherwise returns the default value.

public static T? TryGet<T>(this IDictionary<string, object> values, string key) where T : struct

Parameters

values IDictionary<string, object>

The dictionary for the lookup.

key string

The key to look for.

Returns

T?

A nullable struct type.

Type Parameters

T

The struct type.