mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-03 02:27:08 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Release notes * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CSharp;
|
|
using Microsoft.CodeAnalysis.Testing;
|
|
using Microsoft.CodeAnalysis.Text;
|
|
|
|
namespace Robust.Analyzers.Tests;
|
|
|
|
public static class TestHelper
|
|
{
|
|
public static void AddEmbeddedSources(SolutionState state, params string[] embeddedFiles)
|
|
{
|
|
AddEmbeddedSources(state, (IEnumerable<string>) embeddedFiles);
|
|
}
|
|
|
|
public static void AddEmbeddedSources(SolutionState state, IEnumerable<string> embeddedFiles)
|
|
{
|
|
foreach (var fileName in embeddedFiles)
|
|
{
|
|
state.Sources.Add((fileName, GetEmbeddedFile(fileName)));
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<SyntaxTree> GetEmbeddedSyntaxTrees(params string[] embeddedFiles)
|
|
{
|
|
return embeddedFiles.Select(fileName => CSharpSyntaxTree.ParseText(GetEmbeddedFile(fileName)));
|
|
}
|
|
|
|
private static SourceText GetEmbeddedFile(string fileName)
|
|
{
|
|
using var stream = typeof(TestHelper).Assembly.GetManifestResourceStream(fileName)!;
|
|
return SourceText.From(stream);
|
|
}
|
|
}
|