mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* 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
40 lines
1.1 KiB
C#
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>());
|
|
}
|
|
}
|