Struct Unit
A type with only one value.
Assembly: Recore.dll
Syntax
public struct Unit : IEquatable<Unit>
Examples
Imagine a type ApiResult<T>
that wraps the deserialized JSON response from a REST API.
Without Unit
, you'd have to define a separate, non-generic ApiResult
type for when the response doesn't have a body:
ApiResult postResult = await PostPersonAsync(person);
ApiResult<Person> getResult = await GetPersonAsync(id);
With Unit
, you can just reuse the same type:
ApiResult<Unit> postResult = await PostPersonAsync(person);
ApiResult<Person> getResult = await GetPersonAsync(id);
In the definition of PostPersonAsync()
, just return Unit.Value
:
ApiResult<Unit> PostPersonAsync(Person person)
{
// ...
return new ApiResult<Unit>(Unit.Value);
}
Properties
|
Improve this Doc
View Source
Value
The singleton Unit value.
Declaration
public static Unit Value { get; }
Property Value
Methods
|
Improve this Doc
View Source
Close(Action)
Converts a return type of Void to a return type of Unit.
Declaration
public static Func<Unit> Close(Action action)
Parameters
Type |
Name |
Description |
Action |
action |
|
Returns
|
Improve this Doc
View Source
Equals(Unit)
Two unit instances are always equal.
Declaration
public bool Equals(Unit other)
Parameters
Type |
Name |
Description |
Unit |
other |
|
Returns
|
Improve this Doc
View Source
Equals(Object)
Determines whether another object is the unit value.
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
|
Returns
Overrides
|
Improve this Doc
View Source
GetHashCode()
Returns the hash code of the unit value.
Declaration
public override int GetHashCode()
Returns
Overrides
|
Improve this Doc
View Source
ToString()
Returns a string representation of the unit value.
Declaration
public override string ToString()
Returns
Overrides
Operators
|
Improve this Doc
View Source
Equality(Unit, Unit)
Two unit instances are always equal.
Declaration
public static bool operator ==(Unit lhs, Unit rhs)
Parameters
Returns
|
Improve this Doc
View Source
Inequality(Unit, Unit)
Two unit instances are always equal.
Declaration
public static bool operator !=(Unit lhs, Unit rhs)
Parameters
Returns
Implements
Extension Methods