Struct PrimitiveValue
A union holding a primitive value.
Namespace: UnityEngine.InputSystem.Utilities
Assembly: Unity.InputSystem.dll
Syntax
public struct PrimitiveValue : IEquatable<PrimitiveValue>, IConvertible
Remarks
This structure is used for storing things such as default states for controls (see defaultState). It can store one value of any primitive, non-reference C# type (bool, char, int, float, etc).
Constructors
PrimitiveValue(bool)
Create a PrimitiveValue holding a bool.
Declaration
public PrimitiveValue(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | A boolean value. |
PrimitiveValue(byte)
Create a PrimitiveValue holding a byte.
Declaration
public PrimitiveValue(byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | value | A byte value. |
PrimitiveValue(char)
Create a PrimitiveValue holding a character.
Declaration
public PrimitiveValue(char value)
Parameters
| Type | Name | Description |
|---|---|---|
| char | value | A character. |
PrimitiveValue(double)
Create a PrimitiveValue holding a double.
Declaration
public PrimitiveValue(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | A double value. |
PrimitiveValue(short)
Create a PrimitiveValue holding a short.
Declaration
public PrimitiveValue(short value)
Parameters
| Type | Name | Description |
|---|---|---|
| short | value | A short value. |
PrimitiveValue(int)
Create a PrimitiveValue holding an int.
Declaration
public PrimitiveValue(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | An int value. |
PrimitiveValue(long)
Create a PrimitiveValue holding a long.
Declaration
public PrimitiveValue(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | A long value. |
PrimitiveValue(sbyte)
Create a PrimitiveValue holding a signed byte.
Declaration
public PrimitiveValue(sbyte value)
Parameters
| Type | Name | Description |
|---|---|---|
| sbyte | value | A signed byte value. |
PrimitiveValue(float)
Create a PrimitiveValue holding a float.
Declaration
public PrimitiveValue(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | A float value. |
PrimitiveValue(ushort)
Create a PrimitiveValue holding an unsigned short.
Declaration
public PrimitiveValue(ushort value)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | value | An unsigned short value. |
PrimitiveValue(uint)
Create a PrimitiveValue holding an unsigned int.
Declaration
public PrimitiveValue(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | An unsigned int value. |
PrimitiveValue(ulong)
Create a PrimitiveValue holding a ulong.
Declaration
public PrimitiveValue(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | An unsigned long value. |
Properties
isEmpty
Declaration
public bool isEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool | Whether the struct is holding a value or not. |
type
Type of value stored in the struct. Empty if the struct does not hold a value (i.e. has been default-initialized).
Declaration
public TypeCode type { get; }
Property Value
| Type | Description |
|---|---|
| TypeCode | Type of value stored in the struct. |
Methods
ConvertTo(TypeCode)
Convert to another type of value.
Declaration
public PrimitiveValue ConvertTo(TypeCode type)
Parameters
| Type | Name | Description |
|---|---|---|
| TypeCode | type | Type of value to convert to. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | The converted value. |
Remarks
This method simply calls the other conversion methods (ToBoolean(IFormatProvider),
ToChar(IFormatProvider), etc) based on the current type of value. ArgumentException
is thrown if there is no conversion from the current to the requested type.
Every value can be converted to TypeCode.Empty.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | There is no conversion from the
PrimitiveValue's current type to
|
See Also
Equals(object)
Compare this value to the value of obj.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | Either another PrimitiveValue or a boxed primitive value such as a byte, bool, etc. |
Returns
| Type | Description |
|---|---|
| bool | True if the two values are equal. |
Overrides
Remarks
If obj is a boxed primitive value, it is automatically
converted to a PrimitiveValue.
Equals(PrimitiveValue)
Compare this value to other.
Declaration
public bool Equals(PrimitiveValue other)
Parameters
| Type | Name | Description |
|---|---|---|
| PrimitiveValue | other | Another value. |
Returns
| Type | Description |
|---|---|
| bool | True if the two values are equal. |
Remarks
Equality is based on type and contents. The types of both values must be identical and the memory contents of each value must be bit-wise identical (i.e. things such as floating-point epsilons are not taken into account).
FromBoolean(bool)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromBoolean(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromByte(byte)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromByte(byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromChar(char)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromChar(char value)
Parameters
| Type | Name | Description |
|---|---|---|
| char | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromDouble(double)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromDouble(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromInt16(short)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromInt16(short value)
Parameters
| Type | Name | Description |
|---|---|---|
| short | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromInt32(int)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromInt32(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromInt64(long)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromInt64(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromObject(object)
Create a PrimitiveValue from a boxed value.
Declaration
public static PrimitiveValue FromObject(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | A value. If |
Returns
| Type | Description |
|---|---|
| PrimitiveValue |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | No conversion exists from the type of |
FromSByte(sbyte)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromSByte(sbyte value)
Parameters
| Type | Name | Description |
|---|---|---|
| sbyte | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromSingle(float)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromSingle(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromString(string)
Parse the given string into a PrimitiveValue.
Declaration
public static PrimitiveValue FromString(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | A string containing a value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | The PrimitiveValue parsed from the string. |
Remarks
Integers are parsed as longs. Floating-point numbers are parsed as doubles. Hexadecimal notation is supported for integers.
See Also
FromUInt16(ushort)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromUInt16(ushort value)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromUInt32(uint)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromUInt32(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
FromUInt64(ulong)
Constructs a PrimitiveValue from value.
Declaration
public static PrimitiveValue FromUInt64(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to be stored in the returned |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
From<TValue>(TValue)
Create a PrimitiveValue from the given "blittable"/struct value.
Declaration
public static PrimitiveValue From<TValue>(TValue value) where TValue : struct
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | A value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | The PrimitiveValue converted from |
Type Parameters
| Name | Description |
|---|---|
| TValue | Type of value to convert. Must be either an |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | No conversion exists from the given |
GetHashCode()
Compute a hash code for the value.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code. |
Overrides
GetTypeCode()
Equivalent to type.
Declaration
public TypeCode GetTypeCode()
Returns
| Type | Description |
|---|---|
| TypeCode | Type code for value stored in struct. |
ToBoolean(IFormatProvider)
Convert the value to a boolean.
Declaration
public bool ToBoolean(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| bool | Converted boolean value. |
ToByte(IFormatProvider)
Convert the value to a byte.
Declaration
public byte ToByte(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| byte | Converted byte value. |
ToChar(IFormatProvider)
Convert the value to a char.
Declaration
public char ToChar(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| char | Converted char value. |
ToDateTime(IFormatProvider)
Not supported. Throws NotSupportedException.
Declaration
public DateTime ToDateTime(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| DateTime | Does not return. |
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Always thrown. |
ToDecimal(IFormatProvider)
Convert the value to a decimal.
Declaration
public decimal ToDecimal(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| decimal | Value converted to decimal format. |
ToDouble(IFormatProvider)
Convert the value to a double.
Declaration
public double ToDouble(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| double | Converted double value. |
ToInt16(IFormatProvider)
Convert the value to a short.
Declaration
public short ToInt16(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| short | Converted |
ToInt32(IFormatProvider)
Convert the value to an int
Declaration
public int ToInt32(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| int | Converted |
ToInt64(IFormatProvider)
Convert the value to a long
Declaration
public long ToInt64(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| long | Converted |
ToObject()
Return a boxed version of the value.
Declaration
public object ToObject()
Returns
| Type | Description |
|---|---|
| object | A boxed GC heap object. |
Remarks
This method always allocates GC heap memory.
ToSByte(IFormatProvider)
Convert the value to a sbyte.
Declaration
public sbyte ToSByte(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| sbyte | Converted |
ToSingle(IFormatProvider)
Convert the value to a float.
Declaration
public float ToSingle(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| float | Converted |
ToString()
Return a string representation of the value.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of the value. |
Overrides
Remarks
String versions of PrimitiveValues are always culture invariant. This means that floating-point values, for example, will not the decimal separator of the current culture.
See Also
ToString(IFormatProvider)
Convert the value to a string.
Declaration
public string ToString(IFormatProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| string | Converted |
Remarks
Same as calling ToString().
ToType(Type, IFormatProvider)
Not supported.
Declaration
public object ToType(Type conversionType, IFormatProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | conversionType | Ignored. |
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| object | Does not return. |
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Always thrown. |
ToUInt16(IFormatProvider)
Convert the value to a ushort.
Declaration
public ushort ToUInt16(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| ushort | Converted |
ToUInt32(IFormatProvider)
Convert the value to a uint.
Declaration
public uint ToUInt32(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| uint | Converted |
ToUInt64(IFormatProvider)
Convert the value to a ulong.
Declaration
public ulong ToUInt64(IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | provider | Ignored. |
Returns
| Type | Description |
|---|---|
| ulong | Converted |
Operators
operator ==(PrimitiveValue, PrimitiveValue)
Compare two PrimitiveValues for equality.
Declaration
public static bool operator ==(PrimitiveValue left, PrimitiveValue right)
Parameters
| Type | Name | Description |
|---|---|---|
| PrimitiveValue | left | First value. |
| PrimitiveValue | right | Second value. |
Returns
| Type | Description |
|---|---|
| bool | True if the two values are equal. |
See Also
implicit operator PrimitiveValue(bool)
Create a PrimitiveValue holding a bool.
Declaration
public static implicit operator PrimitiveValue(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | A boolean value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(byte)
Create a PrimitiveValue holding a byte.
Declaration
public static implicit operator PrimitiveValue(byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | value | A byte value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(char)
Create a PrimitiveValue holding a character.
Declaration
public static implicit operator PrimitiveValue(char value)
Parameters
| Type | Name | Description |
|---|---|---|
| char | value | A character. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(double)
Create a PrimitiveValue holding a double.
Declaration
public static implicit operator PrimitiveValue(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | A double value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(short)
Create a PrimitiveValue holding a short.
Declaration
public static implicit operator PrimitiveValue(short value)
Parameters
| Type | Name | Description |
|---|---|---|
| short | value | A short value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(int)
Create a PrimitiveValue holding an int.
Declaration
public static implicit operator PrimitiveValue(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | An int value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(long)
Create a PrimitiveValue holding a long.
Declaration
public static implicit operator PrimitiveValue(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | A long value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(sbyte)
Create a PrimitiveValue holding a signed byte.
Declaration
public static implicit operator PrimitiveValue(sbyte value)
Parameters
| Type | Name | Description |
|---|---|---|
| sbyte | value | A signed byte value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(float)
Create a PrimitiveValue holding a float.
Declaration
public static implicit operator PrimitiveValue(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | A float value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(ushort)
Create a PrimitiveValue holding an unsigned short.
Declaration
public static implicit operator PrimitiveValue(ushort value)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | value | An unsigned short value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(uint)
Create a PrimitiveValue holding an unsigned int.
Declaration
public static implicit operator PrimitiveValue(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | An unsigned int value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
implicit operator PrimitiveValue(ulong)
Create a PrimitiveValue holding a ulong.
Declaration
public static implicit operator PrimitiveValue(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | An unsigned long value. |
Returns
| Type | Description |
|---|---|
| PrimitiveValue | A |
operator !=(PrimitiveValue, PrimitiveValue)
Compare two PrimitiveValues for inequality.
Declaration
public static bool operator !=(PrimitiveValue left, PrimitiveValue right)
Parameters
| Type | Name | Description |
|---|---|---|
| PrimitiveValue | left | First value. |
| PrimitiveValue | right | Second value. |
Returns
| Type | Description |
|---|---|
| bool | True if the two values are not equal. |