using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using Robust.Shared.Toolshed.TypeParsers; namespace Robust.Shared.Toolshed.Commands.Math; [ToolshedCommand] public sealed class CheckedToCommand : ToolshedCommand { private static Type[] _parsers = [typeof(TypeTypeParser)]; public override Type[] TypeParameterParsers => _parsers; [CommandImplementation, TakesPipedTypeAsGeneric] public TOut Operation([PipedArgument] T x) where TOut: INumberBase where T : INumberBase { return TOut.CreateChecked(x); } [CommandImplementation, TakesPipedTypeAsGeneric] public IEnumerable Operation([PipedArgument] IEnumerable x) where TOut: INumberBase where T : INumberBase => x.Select(Operation); } [ToolshedCommand] public sealed class SaturateToCommand : ToolshedCommand { private static Type[] _parsers = [typeof(TypeTypeParser)]; public override Type[] TypeParameterParsers => _parsers; [CommandImplementation, TakesPipedTypeAsGeneric] public TOut Operation([PipedArgument] T x) where TOut: INumberBase where T : INumberBase { return TOut.CreateSaturating(x); } [CommandImplementation, TakesPipedTypeAsGeneric] public IEnumerable Operation([PipedArgument] IEnumerable x) where TOut: INumberBase where T : INumberBase => x.Select(Operation); } [ToolshedCommand] public sealed class TruncToCommand : ToolshedCommand { private static Type[] _parsers = [typeof(TypeTypeParser)]; public override Type[] TypeParameterParsers => _parsers; [CommandImplementation, TakesPipedTypeAsGeneric] public TOut Operation([PipedArgument] T x) where TOut: INumberBase where T : INumberBase { return TOut.CreateTruncating(x); } [CommandImplementation, TakesPipedTypeAsGeneric] public IEnumerable Operation([PipedArgument] IEnumerable x) where TOut: INumberBase where T : INumberBase => x.Select(Operation); }