public readonly bool TryGetValue()

in sdk/core/Azure.Core.Experimental/src/Variant/Variant.cs [1082:1130]


        public readonly bool TryGetValue<T>(out T value)
        {
            bool success;

            // Checking the type gets all of the non-relevant compares elided by the JIT
            if (_object is not null && ((typeof(T) == typeof(bool) && _object == TypeFlags.Boolean)
                || (typeof(T) == typeof(byte) && _object == TypeFlags.Byte)
                || (typeof(T) == typeof(char) && _object == TypeFlags.Char)
                || (typeof(T) == typeof(double) && _object == TypeFlags.Double)
                || (typeof(T) == typeof(short) && _object == TypeFlags.Int16)
                || (typeof(T) == typeof(int) && _object == TypeFlags.Int32)
                || (typeof(T) == typeof(long) && _object == TypeFlags.Int64)
                || (typeof(T) == typeof(sbyte) && _object == TypeFlags.SByte)
                || (typeof(T) == typeof(float) && _object == TypeFlags.Single)
                || (typeof(T) == typeof(ushort) && _object == TypeFlags.UInt16)
                || (typeof(T) == typeof(uint) && _object == TypeFlags.UInt32)
                || (typeof(T) == typeof(ulong) && _object == TypeFlags.UInt64)))
            {
                value = CastTo<T>();
                success = true;
            }
            else if (typeof(T) == typeof(DateTime) && _object == TypeFlags.DateTime)
            {
                value = Unsafe.As<DateTime, T>(ref Unsafe.AsRef(in _union.DateTime));
                success = true;
            }
            else if (typeof(T) == typeof(DateTimeOffset) && _object == TypeFlags.DateTimeOffset)
            {
                DateTimeOffset dateTimeOffset = new(_union.Ticks, TimeSpan.Zero);
                value = Unsafe.As<DateTimeOffset, T>(ref Unsafe.AsRef(in dateTimeOffset));
                success = true;
            }
            else if (typeof(T) == typeof(DateTimeOffset) && _object == TypeFlags.PackedDateTimeOffset)
            {
                DateTimeOffset dateTimeOffset = _union.PackedDateTimeOffset.Extract();
                value = Unsafe.As<DateTimeOffset, T>(ref Unsafe.AsRef(in dateTimeOffset));
                success = true;
            }
            else if (typeof(T).IsValueType)
            {
                success = TryGetValueSlow(out value);
            }
            else
            {
                success = TryGetObjectSlow(out value);
            }

            return success;
        }