docs.unity3d.com
    Show / Hide Table of Contents

    Struct PrimitiveValue

    A union holding a primitive value.

    Namespace: UnityEngine.InputSystem.Utilities
    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(Boolean)

    Create a PrimitiveValue holding a bool.

    Declaration
    public PrimitiveValue(bool value)
    Parameters
    Type Name Description
    Boolean 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(Int16)

    Create a PrimitiveValue holding a short.

    Declaration
    public PrimitiveValue(short value)
    Parameters
    Type Name Description
    Int16 value

    A short value.

    PrimitiveValue(Int32)

    Create a PrimitiveValue holding an int.

    Declaration
    public PrimitiveValue(int value)
    Parameters
    Type Name Description
    Int32 value

    An int value.

    PrimitiveValue(Int64)

    Create a PrimitiveValue holding a long.

    Declaration
    public PrimitiveValue(long value)
    Parameters
    Type Name Description
    Int64 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(Single)

    Create a PrimitiveValue holding a float.

    Declaration
    public PrimitiveValue(float value)
    Parameters
    Type Name Description
    Single value

    A float value.

    PrimitiveValue(UInt16)

    Create a PrimitiveValue holding an unsigned short.

    Declaration
    public PrimitiveValue(ushort value)
    Parameters
    Type Name Description
    UInt16 value

    An unsigned short value.

    PrimitiveValue(UInt32)

    Create a PrimitiveValue holding an unsigned int.

    Declaration
    public PrimitiveValue(uint value)
    Parameters
    Type Name Description
    UInt32 value

    An unsigned int value.

    PrimitiveValue(UInt64)

    Create a PrimitiveValue holding a ulong.

    Declaration
    public PrimitiveValue(ulong value)
    Parameters
    Type Name Description
    UInt64 value

    An unsigned long value.

    Properties

    isEmpty

    If true, the struct does not contain a primitive value (i.e. has type ).

    Declaration
    public bool isEmpty { get; }
    Property Value
    Type Description
    Boolean

    Whether the struct is holding a value or not.

    type

    Type of value stored in the struct. 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.

    See Also
    ToBoolean(IFormatProvider)
    ToChar(IFormatProvider)
    ToByte(IFormatProvider)
    ToSByte(IFormatProvider)
    ToInt16(IFormatProvider)
    ToInt32(IFormatProvider)
    ToInt64(IFormatProvider)
    ToUInt16(IFormatProvider)
    ToUInt32(IFormatProvider)
    ToUInt64(IFormatProvider)
    ToSingle(IFormatProvider)
    ToDouble(IFormatProvider)

    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
    Boolean

    True if the two values are equal.

    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
    Boolean

    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).

    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 value. If it is an enum type, the PrimitiveValue will hold a value of the enum's underlying type (i.e. Type.GetEnumUnderlyingType).

    Type Parameters
    Name Description
    TValue

    Type of value to convert. Must be either an enum or one of the C# primitive value types (bool, int, float, etc.).

    FromBoolean(Boolean)

    Declaration
    public static PrimitiveValue FromBoolean(bool value)
    Parameters
    Type Name Description
    Boolean value
    Returns
    Type Description
    PrimitiveValue

    FromByte(Byte)

    Declaration
    public static PrimitiveValue FromByte(byte value)
    Parameters
    Type Name Description
    Byte value
    Returns
    Type Description
    PrimitiveValue

    FromChar(Char)

    Declaration
    public static PrimitiveValue FromChar(char value)
    Parameters
    Type Name Description
    Char value
    Returns
    Type Description
    PrimitiveValue

    FromDouble(Double)

    Declaration
    public static PrimitiveValue FromDouble(double value)
    Parameters
    Type Name Description
    Double value
    Returns
    Type Description
    PrimitiveValue

    FromInt16(Int16)

    Declaration
    public static PrimitiveValue FromInt16(short value)
    Parameters
    Type Name Description
    Int16 value
    Returns
    Type Description
    PrimitiveValue

    FromInt32(Int32)

    Declaration
    public static PrimitiveValue FromInt32(int value)
    Parameters
    Type Name Description
    Int32 value
    Returns
    Type Description
    PrimitiveValue

    FromInt64(Int64)

    Declaration
    public static PrimitiveValue FromInt64(long value)
    Parameters
    Type Name Description
    Int64 value
    Returns
    Type Description
    PrimitiveValue

    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 null, the result will be default(PrimitiveValue). If it is a string, FromString(String) is used. Otherwise must be either an enum or one of the C# primitive value types (bool, int, float, etc.). If it is an enum type, the PrimitiveValue will hold a value of the enum's underlying type (i.e. Type.GetEnumUnderlyingType).

    Returns
    Type Description
    PrimitiveValue

    FromSByte(SByte)

    Declaration
    public static PrimitiveValue FromSByte(sbyte value)
    Parameters
    Type Name Description
    SByte value
    Returns
    Type Description
    PrimitiveValue

    FromSingle(Single)

    Declaration
    public static PrimitiveValue FromSingle(float value)
    Parameters
    Type Name Description
    Single value
    Returns
    Type Description
    PrimitiveValue

    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
    ToString()

    FromUInt16(UInt16)

    Declaration
    public static PrimitiveValue FromUInt16(ushort value)
    Parameters
    Type Name Description
    UInt16 value
    Returns
    Type Description
    PrimitiveValue

    FromUInt32(UInt32)

    Declaration
    public static PrimitiveValue FromUInt32(uint value)
    Parameters
    Type Name Description
    UInt32 value
    Returns
    Type Description
    PrimitiveValue

    FromUInt64(UInt64)

    Declaration
    public static PrimitiveValue FromUInt64(ulong value)
    Parameters
    Type Name Description
    UInt64 value
    Returns
    Type Description
    PrimitiveValue

    GetHashCode()

    Compute a hash code for the value.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    A hash code.

    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
    Boolean

    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.

    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
    Int16

    Converted short value.

    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
    Int32

    Converted int value.

    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
    Int64

    Converted long value.

    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 sbyte value.

    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
    Single

    Converted float value.

    ToString()

    Return a string representation of the value.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String

    A string representation of the value.

    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
    FromString(String)

    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 string value.

    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.

    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
    UInt16

    Converted ushort value.

    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
    UInt32

    Converted uint value.

    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
    UInt64

    Converted ulong value.

    Operators

    Equality(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
    Boolean

    True if the two values are equal.

    See Also
    Equals(PrimitiveValue)

    Implicit(Boolean to PrimitiveValue)

    Create a PrimitiveValue holding a bool.

    Declaration
    public static implicit operator PrimitiveValue(bool value)
    Parameters
    Type Name Description
    Boolean value

    A boolean value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(Byte to PrimitiveValue)

    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

    Implicit(Char to PrimitiveValue)

    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

    Implicit(Double to PrimitiveValue)

    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

    Implicit(Int16 to PrimitiveValue)

    Create a PrimitiveValue holding a short.

    Declaration
    public static implicit operator PrimitiveValue(short value)
    Parameters
    Type Name Description
    Int16 value

    A short value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(Int32 to PrimitiveValue)

    Create a PrimitiveValue holding an int.

    Declaration
    public static implicit operator PrimitiveValue(int value)
    Parameters
    Type Name Description
    Int32 value

    An int value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(Int64 to PrimitiveValue)

    Create a PrimitiveValue holding a long.

    Declaration
    public static implicit operator PrimitiveValue(long value)
    Parameters
    Type Name Description
    Int64 value

    A long value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(SByte to PrimitiveValue)

    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

    Implicit(Single to PrimitiveValue)

    Create a PrimitiveValue holding a float.

    Declaration
    public static implicit operator PrimitiveValue(float value)
    Parameters
    Type Name Description
    Single value

    A float value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(UInt16 to PrimitiveValue)

    Create a PrimitiveValue holding an unsigned short.

    Declaration
    public static implicit operator PrimitiveValue(ushort value)
    Parameters
    Type Name Description
    UInt16 value

    An unsigned short value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(UInt32 to PrimitiveValue)

    Create a PrimitiveValue holding an unsigned int.

    Declaration
    public static implicit operator PrimitiveValue(uint value)
    Parameters
    Type Name Description
    UInt32 value

    An unsigned int value.

    Returns
    Type Description
    PrimitiveValue

    Implicit(UInt64 to PrimitiveValue)

    Create a PrimitiveValue holding a ulong.

    Declaration
    public static implicit operator PrimitiveValue(ulong value)
    Parameters
    Type Name Description
    UInt64 value

    An unsigned long value.

    Returns
    Type Description
    PrimitiveValue

    Inequality(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
    Boolean

    True if the two values are not equal.

    See Also
    Equals(PrimitiveValue)
    In This Article
    • Constructors
      • PrimitiveValue(Boolean)
      • PrimitiveValue(Byte)
      • PrimitiveValue(Char)
      • PrimitiveValue(Double)
      • PrimitiveValue(Int16)
      • PrimitiveValue(Int32)
      • PrimitiveValue(Int64)
      • PrimitiveValue(SByte)
      • PrimitiveValue(Single)
      • PrimitiveValue(UInt16)
      • PrimitiveValue(UInt32)
      • PrimitiveValue(UInt64)
    • Properties
      • isEmpty
      • type
    • Methods
      • ConvertTo(TypeCode)
      • Equals(Object)
      • Equals(PrimitiveValue)
      • From<TValue>(TValue)
      • FromBoolean(Boolean)
      • FromByte(Byte)
      • FromChar(Char)
      • FromDouble(Double)
      • FromInt16(Int16)
      • FromInt32(Int32)
      • FromInt64(Int64)
      • FromObject(Object)
      • FromSByte(SByte)
      • FromSingle(Single)
      • FromString(String)
      • FromUInt16(UInt16)
      • FromUInt32(UInt32)
      • FromUInt64(UInt64)
      • GetHashCode()
      • GetTypeCode()
      • ToBoolean(IFormatProvider)
      • ToByte(IFormatProvider)
      • ToChar(IFormatProvider)
      • ToDateTime(IFormatProvider)
      • ToDecimal(IFormatProvider)
      • ToDouble(IFormatProvider)
      • ToInt16(IFormatProvider)
      • ToInt32(IFormatProvider)
      • ToInt64(IFormatProvider)
      • ToObject()
      • ToSByte(IFormatProvider)
      • ToSingle(IFormatProvider)
      • ToString()
      • ToString(IFormatProvider)
      • ToType(Type, IFormatProvider)
      • ToUInt16(IFormatProvider)
      • ToUInt32(IFormatProvider)
      • ToUInt64(IFormatProvider)
    • Operators
      • Equality(PrimitiveValue, PrimitiveValue)
      • Implicit(Boolean to PrimitiveValue)
      • Implicit(Byte to PrimitiveValue)
      • Implicit(Char to PrimitiveValue)
      • Implicit(Double to PrimitiveValue)
      • Implicit(Int16 to PrimitiveValue)
      • Implicit(Int32 to PrimitiveValue)
      • Implicit(Int64 to PrimitiveValue)
      • Implicit(SByte to PrimitiveValue)
      • Implicit(Single to PrimitiveValue)
      • Implicit(UInt16 to PrimitiveValue)
      • Implicit(UInt32 to PrimitiveValue)
      • Implicit(UInt64 to PrimitiveValue)
      • Inequality(PrimitiveValue, PrimitiveValue)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023