src/AnvilPacker/Data/NBT.cs
/// <summary> Returns the underlying tag value, converted to T. </summary>
/// <exception cref="InvalidCastException">If the value couldn't be converted to <typeparamref name="T"/></exception>
Returns the underlying tag value, converted to T.
Returns the underlying tag value converted to T .
public override T Value<T>()
        {
            if (this is PrimitiveTag<T> pt) {
                return pt.Value;
            }
            if (typeof(T) == typeof(bool))   return (T)(object)((byte)GetValue() != 0);
            if (typeof(T) == typeof(sbyte))  return (T)(object)((sbyte)(byte)GetValue());
            if (typeof(T) == typeof(ushort)) return (T)(object)((ushort)(short)GetValue());
            if (typeof(T) == typeof(uint))   return (T)(object)((uint)(int)GetValue());
            if (typeof(T) == typeof(ulong))  return (T)(object)((ulong)(long)GetValue());
            if (typeof(T) == typeof(Array))  return (T)(object)GetValue();
            return (T)Convert.ChangeType(GetValue(), typeof(T));
        }
public override T Value < T > ( ) { if ( this is PrimitiveTag < T > pt ) { return pt . Value ; } if ( typeof ( T ) == typeof ( bool ) ) return ( T ) ( object ) ( ( byte ) GetValue ( ) != 0 ) ; if ( typeof ( T ) == typeof ( sbyte ) ) return ( T ) ( object ) ( ( sbyte ) ( byte ) GetValue ( ) ) ; if ( typeof ( T ) == typeof ( ushort ) ) return ( T ) ( object ) ( ( ushort ) ( short ) GetValue ( ) ) ; if ( typeof ( T ) == typeof ( uint ) ) return ( T ) ( object ) ( ( uint ) ( int ) GetValue ( ) ) ; if ( typeof ( T ) == typeof ( ulong ) ) return ( T ) ( object ) ( ( ulong ) ( long ) GetValue ( ) ) ; if ( typeof ( T ) == typeof ( Array ) ) return ( T ) ( object ) GetValue ( ) ; return ( T ) Convert . ChangeType ( GetValue ( ) , typeof ( T ) ) ; }
Returns the underlying tag value, converted to T.
Returns the underlying tag value converted to T .
If the value couldn't be converted to
If the value couldn ' t be converted to