mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Adds help method to C# scripting. (#2368)
This commit is contained in:
committed by
GitHub
parent
a54283e637
commit
eecb104cc5
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.Scripting
|
||||
{
|
||||
@@ -15,6 +19,9 @@ namespace Robust.Shared.Scripting
|
||||
[SuppressMessage("ReSharper", "CA1822")]
|
||||
public abstract class ScriptGlobalsShared
|
||||
{
|
||||
private const BindingFlags DefaultHelpFlags =
|
||||
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
||||
|
||||
[field: Dependency] public IEntityManager ent { get; } = default!;
|
||||
[field: Dependency] public IPrototypeManager prot { get; } = default!;
|
||||
[field: Dependency] public IMapManager map { get; } = default!;
|
||||
@@ -103,6 +110,50 @@ namespace Robust.Shared.Scripting
|
||||
return m!.Invoke(target, args);
|
||||
}
|
||||
|
||||
public void help()
|
||||
{
|
||||
help(GetType(), DefaultHelpFlags &~ BindingFlags.NonPublic, false, false);
|
||||
}
|
||||
|
||||
public void help(Type type, BindingFlags flags = DefaultHelpFlags, bool specialNameMethods = true, bool modifiers = true)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
foreach (var member in type.GetMembers(flags))
|
||||
{
|
||||
switch (member.MemberType)
|
||||
{
|
||||
case MemberTypes.Method:
|
||||
var method = (MethodInfo) member;
|
||||
|
||||
if (!specialNameMethods && method.IsSpecialName)
|
||||
continue; // Let's not print constructors, property methods, etc.
|
||||
|
||||
builder.Append(method.PrintMethodSignature(modifiers));
|
||||
builder.AppendLine(";");
|
||||
break;
|
||||
|
||||
case MemberTypes.Property:
|
||||
builder.AppendLine(((PropertyInfo)member).PrintPropertySignature(modifiers, true));
|
||||
break;
|
||||
|
||||
case MemberTypes.Field:
|
||||
builder.Append(((FieldInfo) member).PrintFieldSignature(modifiers));
|
||||
builder.AppendLine(";");
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
// This is slow, so do it all at once.
|
||||
WriteSyntax(builder.ToString());
|
||||
}
|
||||
|
||||
protected abstract void WriteSyntax(object toString);
|
||||
public abstract void write(object toString);
|
||||
public abstract void show(object obj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user