CGroupValue<T> Struct

Holds the value of a cgroup interface file together with the reason a value may be absent.

public readonly struct CGroupValue<T> : IEquatable<CGroupValue<T>>

Type parameters

T
The type of the parsed value.

Remarks

A cgroup getter has four possible outcomes, and reporting them all as null makes them indistinguishable: a caller cannot tell "the memory controller is not enabled" from "memory is unlimited". CGroupValue<T>.State keeps them apart. The default value of this type is CGroupValueState.Unavailable.

Implements

Properties

NameDescription
IsConfiguredGets a value indicating whether the interface file holds a value.
RawValueGets the content of the interface file with leading and trailing whitespace removed, or null when the file does not exist.
StateGets what the interface file holds.
ValueGets the value held by the interface file.

IsConfigured

CGroupValue.cs

Gets a value indicating whether the interface file holds a value.

public bool IsConfigured { get; }

Property value

bool

Gets the content of the interface file with leading and trailing whitespace removed, or null when the file does not exist.

public string? RawValue { get; }

Property value

string?

Gets what the interface file holds.

public CGroupValueState State { get; }

Property value

CGroupValueState

Gets the value held by the interface file.

public T Value { get; }

Property value

T

Exceptions

InvalidOperationException
The interface file does not hold a value. Use CGroupValue<T>.State or CGroupValue<T>.TryGetValue to handle that case.

Methods

NameDescription
Equals(CGroupValue<T>)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Indicates whether this instance and a specified object are equal.
GetHashCode()Returns the hash code for this instance.
GetValueOrDefault()Gets the value held by the interface file, or the default value of T when it holds none.
GetValueOrDefault(T)Gets the value held by the interface file, or defaultValue when it holds none.
ToString()Returns a string representation of this value.
TryGetValue(T)Gets the value held by the interface file.

Equals overloads

Equals(CGroupValue<T>)

CGroupValue.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(CGroupValue<T> other)
Parameters
other CGroupValue<T>
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

CGroupValue.cs

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

CGroupValue.cs

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

GetValueOrDefault overloads

GetValueOrDefault()

CGroupValue.cs

Gets the value held by the interface file, or the default value of T when it holds none.

public T? GetValueOrDefault()
Returns

T?

GetValueOrDefault(T)

CGroupValue.cs

Gets the value held by the interface file, or defaultValue when it holds none.

public T GetValueOrDefault(T defaultValue)
Parameters
defaultValue T
The value to return when the interface file holds no value.
Returns

T

ToString()

CGroupValue.cs

Returns a string representation of this value.

public override string ToString()

Returns

string

TryGetValue(T)

CGroupValue.cs

Gets the value held by the interface file.

public bool TryGetValue(out T value)

Parameters

value T
The value when the interface file holds one; otherwise, the default value of T.

Returns

bool true when the interface file holds a value; otherwise, false.

Operators

NameDescription
operator ==(CGroupValue<T>, CGroupValue<T>)Determines whether two values are equal.
operator !=(CGroupValue<T>, CGroupValue<T>)Determines whether two values are different.

operator ==(CGroupValue<T>, CGroupValue<T>)

CGroupValue.cs

Determines whether two values are equal.

public static bool operator ==(CGroupValue<T> left, CGroupValue<T> right)

Parameters

left CGroupValue<T>
The first value to compare.
right CGroupValue<T>
The second value to compare.

Returns

bool

operator !=(CGroupValue<T>, CGroupValue<T>)

CGroupValue.cs

Determines whether two values are different.

public static bool operator !=(CGroupValue<T> left, CGroupValue<T> right)

Parameters

left CGroupValue<T>
The first value to compare.
right CGroupValue<T>
The second value to compare.

Returns

bool