Work around Roslyn scripting bug with ref structs.

This commit is contained in:
Pieter-Jan Briers
2021-02-28 17:27:21 +01:00
parent fefcc7cba3
commit 31716f5104
3 changed files with 20 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.CSharp.Scripting.Hosting;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.CodeAnalysis.Text;
using Robust.Shared.Maths;
@@ -220,5 +221,19 @@ namespace Robust.Shared.Scripting
.AddImports(_defaultImports)
.AddReferences(GetDefaultReferences(reflectionManager));
}
public static string SafeFormat(object obj)
{
// Working "around" https://github.com/dotnet/roslyn/issues/51548
try
{
return CSharpObjectFormatter.Instance.FormatObject(obj);
}
catch (NotSupportedException)
{
return "<CSharpObjectFormatter.FormatObject threw>";
}
}
}
}