Closed Sicos1977 closed 1 year ago
Seems there is already an option to do this
I only needed to create this class
#region Class ForbiddenTypeAnalyzerReference
internal class ForbiddenTypeAnalyzerReference : AnalyzerReference
{
public override string FullPath { get; }
public override object Id { get; }
public override ImmutableArray<DiagnosticAnalyzer> GetAnalyzersForAllLanguages()
{
return ImmutableArray.Create<DiagnosticAnalyzer>(new ForbiddenTypeAnalyzer());
}
public override ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(string language)
{
return ImmutableArray.Create<DiagnosticAnalyzer>(new ForbiddenTypeAnalyzer());
}
}
#endregion
and then reference it like this
var mirrorSharpOptions = new MirrorSharpOptions
{
SelfDebugEnabled = debug,
IncludeExceptionDetails = true
}
.SetupCSharp(m =>
{
m.AnalyzerReferences = m.AnalyzerReferences.Add(new ForbiddenTypeAnalyzerReference());
m.MetadataReferences = m.MetadataReferences.Clear();
foreach (var metadataReference in MetadataReferences.Get)
{
m.AddMetadataReferencesFromFiles(metadataReference);
if (debug)
systemLogs.Insert(ServiceName.Website, $"Adding metadata reference '{metadataReference}'");
}
});
Hi,
I made a class that uses the Roslyn compiler to check if a user is doing some scripting that is not allowed. For example trying to read something from the local filesystem.
At the moment I just check the written schript when the user tries to save it and then show an error when he is doing something that is not allowed.
Is it possbile that you make an extension in Micrrorsharp so that I can inject this class into Roslyn so that the user already gets a warning shown in Mirrorsharp that he is writing code that is not allowed?