enum but with some additional machinery to test for success and to distinguish between a real value and a default-initialized value. This is important because an enum constant of zero is often used to indicate Success.
true), then you can access the value using the Value property.
false), then the OVRResult does not have a value, and it is an error to access the Value property. In this case, the Status property will contain an error code.
HasValue
: bool
[Get] |
Indicates whether the result has a value.
It is an error to access Value when this property is false.
Signature
bool HasValue |
Status
: TStatus
[Get] |
The status of the result.
The status could represent success (see Success) or a failure. If it is a failure, use this property to obtain more detailed error information.
Signature
TStatus Status |
Success
: bool
[Get] | |
Value
: TValue
[Get] |
The value of the result.
Signature
TValue Value |
Equals
(
other
)
|
Signature
bool Equals(OVRResult< TStatus > other) |
Equals
(
obj
)
|
Determines whether the current OVRResult<TStatus> is equal to another object.
Signature
override bool Equals(object obj) Parameters |
Equals
(
other
)
|
Signature
bool Equals(OVRResult< TValue, TStatus > other) Parameters |
Equals
(
obj
)
| |
Equals
()
|
Signature
override bool TStatus other && Equals(other) Parameters otherReturns override bool TStatus other && |
GetHashCode
()
|
Gets a hashcode suitable for use in a Dictionary or HashSet.
Signature
override int GetHashCode() Returns override int
Returns a hashcode suitable for use in a Dictionary or HashSet.
|
GetHashCode
()
|
Gets a hashcode suitable for use in a Dictionary or HashSet.
Signature
override int GetHashCode() Returns override int
Returns a hashcode for this result.
|
ToString
()
|
Generates a string representation of this result object.
The string representation is the stringification of Status, or "(invalid result)" if this result object has not been initialized.
Signature
override string ToString() |
ToString
()
|
Generates a string representation of this result object.
Signature
override string ToString() |
TryGetValue
(
value
)
|
Tries to retrieve the value of the result.
This provides an exception-free method of obtaining the result's Value if one is available.
This allows you to simplify your code. Instead of this:
if (result.HasValue) {
var value = result.Value;
// use value
}
You can instead combine the HasValue check with the extraction of the result:
if (result.TryGetValue(out var value)) {
// use value
}
Signature
bool TryGetValue(out TValue value) Parameters value: out TValue
When this method returns, contains the value of the result if the result was successful; otherwise, the default value.
Returns bool
Returns true if the result was successful and the value is retrieved; otherwise, false.
|
From
(
status
)
| |
From
(
value
, status
)
|
Creates a new OVRResult<TValue, TStatus> with the specified value and status.
Signature
static OVRResult< TValue, TStatus > From(TValue value, TStatus status) Parameters value: TValue
The value.
status: TStatus
The status.
|
FromFailure
(
status
)
|
Creates a new OVRResult<TStatus> with the specified failure status.
Signature
static OVRResult< TStatus > FromFailure(TStatus status) Parameters status: TStatus
The status (must be a valid failure status).
Throws ArgumentException
Thrown when status is not a valid failure status.
|
FromFailure
(
status
)
|
Creates a new OVRResult<TValue, TStatus> with the specified failure status.
Signature
static OVRResult< TValue, TStatus > FromFailure(TStatus status) Parameters status: TStatus
The status (must be a valid failure status).
Returns OVRResult< TValue, TStatus >
Returns a new OVRResult<TValue, TStatus> with the specified status.
Throws ArgumentException
Thrown when status is not a valid failure status.
|
FromSuccess
(
status
)
|
Creates a new OVRResult<TStatus> with the specified success status.
Signature
static OVRResult< TStatus > FromSuccess(TStatus status) Parameters status: TStatus
The status (must be a valid success status).
Throws ArgumentException
Thrown when status is not a valid success status.
|
FromSuccess
(
value
, status
)
|
Creates a new OVRResult<TValue, TStatus> with the specified value and a success status.
Signature
static OVRResult< TValue, TStatus > FromSuccess(TValue value, TStatus status) Parameters value: TValue
The value.
status: TStatus
The status (must be a valid success status).
Returns OVRResult< TValue, TStatus >
Returns a new OVRResult<TValue, TStatus> with the specified value and status.
Throws ArgumentException
Thrown when status is not a valid success status.
|
operator bool
(
value
)
|
Implicitly casts an OVRResult to a bool.
If the OVRResult represents success, then it will convert to true. Otherwise, it will convert to false.
For example, this allows you to write code like:
var result = DoOperation();
if (result) {
Debug.Log("Operation succeeded.");
} else {
Debug.LogError($"Operation failed with error {result.Status}.");
}
Signature
static implicit operator bool(OVRResult< TStatus > value) |
operator bool
(
value
)
|
Implicitly casts an OVRResult to a bool.
If the OVRResult represents success, then it will convert to true. Otherwise, it will convert to false.
For example, this allows you to write code like:
var result = DoOperation();
if (result) {
Debug.Log("Operation succeeded.");
} else {
Debug.LogError($"Operation failed with error {result.Status}.");
}
Signature
static implicit operator bool(OVRResult< TValue, TStatus > value) |
operator OVRResult
(
result
)
|
(Internal) Implicitly converts an OVRPlugin.Result to an OVRResult<TStatus>.
This implicit conversion is provided mostly for internal Meta use (C# requires user-defined conversion operators to be public). It simplifies early returns in methods that return an OVRResult<TStatus> and need to early out when a call fails.
Such methods can simply return the result rather than constructing an OVRResult<TStatus> with a cast.
Signature
static implicit operator OVRResult(OVRPlugin.Result result) Parameters result: OVRPlugin.Result
The result.
|
operator OVRResult< TValue, TStatus >
(
result
)
|
(Internal) Implicitly converts an OVRPlugin.Result to a failed OVRResult<TValue,TStatus>.
This implicit conversion is provided mostly for internal Meta use (C# requires user-defined conversion operators to be public). It simplifies early returns in methods that return an OVRResult<TValue,TStatus> and need to early out when a call fails.
Such methods can simply return the result rather than constructing an OVRResult<TValue,TStatus> with potentially complex type parameters.
Signature
static implicit operator OVRResult< TValue, TStatus >(OVRPlugin.Result result) Parameters result: OVRPlugin.Result
The result, which must represent failure (be less than zero).
Throws ArgumentException
Thrown if result does not represent a failure case.
|