API reference
API reference
Select your platform
No SDKs available
No versions available

OVRResult Struct

Extends IEquatable< OVRResult< TStatus > >, IEquatable< OVRResult< TValue, TStatus > >
Represents the result of an operation.
Represents a result with a value of type TValue and a status code of type TStatus .
An OVRResult<TStatus> is effectively an 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.
Many asynchronous methods return an OVRResult, for example many OVRAnchor and OVRSpatialAnchor methods are asynchronous.
For results that also contain a value, see OVRResult<TValue, TStatus>.
An OVRResult<TValue, TStatus> represents the result of an operation which may fail. If the operation succeeds (Success is true), then you can access the value using the Value property.
If the operation fails (Success is 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.

Properties

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.
If the operation fails (Success is false), then the Status enum indicates a more specific reason for the failure.
Signature
TStatus Status
Success : bool
[Get]
Whether this OVRResult<TStatus> represents a successful result.
Whether this OVRResult<TValue, TStatus> represents a successful result.
This must be true in order to access Value.
Signature
bool Success
Value : TValue
[Get]
The value of the result.
It is an error to access this property unless Success is true. See also TryGetValue.
Signature
TValue Value

Methods

Equals ( other )
Determines whether the current OVRResult<TStatus> is equal to another OVRResult<TStatus>.
Signature
bool Equals(OVRResult< TStatus > other)
Parameters
other: OVRResult< TStatus >  The OVRResult<TStatus> to compare with the current one.
Returns
bool  Returns true if the specified OVRResult<TStatus> is equal to this OVRResult<TStatus>, otherwise false.
Equals ( obj )
Determines whether the current OVRResult<TStatus> is equal to another object.
Signature
override bool Equals(object obj)
Parameters
obj: object  The object to compare with the current OVRResult<TStatus>.
Returns
override bool  Returns true if obj is of type OVRResult<TStatus> and is equal to this OVRResult<TStatus>, otherwise false.
Equals ( other )
Determines whether the current OVRResult<TValue, TStatus> is equal to another OVRResult<TValue, TStatus>.
Signature
bool Equals(OVRResult< TValue, TStatus > other)
Parameters
other: OVRResult< TValue, TStatus >  The OVRResult<TValue, TStatus> to compare with the current one.
Returns
bool  Returns true if the specified OVRResult<TValue, TStatus> is equal to the current OVRResult<TValue, TStatus>; otherwise, false.
Equals ( obj )
Determines whether the current OVRResult<TValue, TStatus> is equal to another object.
Signature
override bool Equals(object obj)
Parameters
obj: object  The object to compare with the current OVRResult<TValue, TStatus>.
Returns
override bool  Returns true if the specified object is equal to the current OVRResult<TValue, TStatus>; otherwise, false.
Equals ()
Signature
override bool TStatus other && Equals(other)
Parameters
other
Returns
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()
Returns
override string  Returns a string representation of this OVRResult<TStatus>
ToString ()
Generates a string representation of this result object.
If this result object has not been initialized, the string is "(invalid result)". Otherwise, if Success is true, then the string is the stringification of the Status and Value. If Success is false, then it is just the stringification of Status.
Signature
override string ToString()
Returns
override string  Returns a string representation of this OVRResult<TStatus>
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.

Static Methods

From ( status )
Creates a new OVRResult<TStatus> with the specified status.
Signature
static OVRResult< TStatus > From(TStatus status)
Parameters
status: TStatus  The status of the result.
Returns
OVRResult< TStatus >  Returns a new OVRResult<TStatus> with the specified 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.
Returns
OVRResult< TValue, TStatus >  Returns a new OVRResult<TValue, TStatus> with the specified value and 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).
Returns
OVRResult< TStatus >  Returns a new OVRResult<TStatus> with the specified 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).
Returns
OVRResult< TStatus >  Returns a new OVRResult<TStatus> with the specified 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)
Parameters
value: OVRResult< TStatus >  The OVRResult to cast.
Returns
implicit  Returns the value of Success.
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)
Parameters
value: OVRResult< TValue, TStatus >  The OVRResult to cast.
Returns
implicit  Returns the value of Success.
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.
Returns
implicit  Returns an OVRResult<TStatus> whose Status is result cast to a TStatus .
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).
Returns
implicit  Returns an OVRResult<TValue,TStatus> whose Success is false.
Throws
ArgumentException  Thrown if result does not represent a failure case.