Files
RobustToolbox/Robust.Shared/Toolshed/ToolshedCommand.Implementations.cs
Leon Friedrich 9af119f57a Toolshed Rejig (#5455)
* Toolshed Rejig

* shorten hint string

* Try fix conflicts. Ill make with work later

* bodge

* Fix ProtoIdTypeParser assert

* comment

* AllEntities

* Remove more linq from WhereCommand

* better help strings

* Add ContainsCommand

* loc strings

* Add contains command description

* Add $self variable

* Errors for writing to readonly variables

* A
2024-12-21 17:49:11 +11:00

40 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Robust.Shared.Utility;
namespace Robust.Shared.Toolshed;
public abstract partial class ToolshedCommand
{
public const BindingFlags MethodFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |
BindingFlags.Instance;
public bool TryGetReturnType(
string? subCommand,
Type? pipedType,
Type[]? typeArguments,
[NotNullWhen(true)] out Type? type)
{
type = null;
if (!CommandImplementors.TryGetValue(subCommand ?? string.Empty, out var impl))
return false;
if (!impl.TryGetConcreteMethod(pipedType, typeArguments, out var method))
return false;
type = method.Value.Info.ReturnType;
return true;
}
internal IEnumerable<MethodInfo> GetGenericImplementations()
{
return GetType()
.GetMethods(MethodFlags)
.Where(x => x.HasCustomAttribute<CommandImplementationAttribute>());
}
}