public static void CreateEnvironmentCA2247()
        {
            var sources = new List <(string name, string content)>();

            for (var i = 0; i < Constants.Number_Of_Code_Files; i++)
            {
                var name = "TypeName" + i;
                sources.Add((name, @$ "
Imports System.Threading.Tasks

Class {name}
    Private Sub M()
        ' Use TCS correctly without options
        Dim a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(Nothing)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(" "hello" ")
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(New Object())
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(42)

        ' Uses TaskCreationOptions correctly
        Dim validEnum = System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(validEnum)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(MyProperty)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(New Object(), validEnum)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(New Object(), System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(New Object(), MyProperty)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(Nothing, validEnum)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(Nothing, System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously)
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(Nothing, MyProperty)

        ' We only pay attention to things of type TaskContinuationOptions
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously.ToString())
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(System.Threading.Tasks.TaskContinuationOptions.RunContinuationsAsynchronously.ToString())
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(CType(System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously, Integer))
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(CType(System.Threading.Tasks.TaskContinuationOptions.RunContinuationsAsynchronously, Integer))

        ' Explicit choice to store into an object ignored
        Dim validObject As Object = System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(validObject)
        Dim invalidObject As Object = System.Threading.Tasks.TaskContinuationOptions.RunContinuationsAsynchronously
        a = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(invalidObject)


        Dim tcs = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(System.Threading.Tasks.TaskContinuationOptions.None)
        tcs = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(System.Threading.Tasks.TaskContinuationOptions.RunContinuationsAsynchronously)
        tcs = New System.Threading.Tasks.TaskCompletionSource(Of Integer)(System.Threading.Tasks.TaskContinuationOptions.AttachedToParent)
    End Sub

    Private MyProperty As System.Threading.Tasks.TaskCreationOptions
End Class
"));
            }

            var compilation = VisualBasicCompilationHelper.CreateAsync(sources.ToArray()).GetAwaiter().GetResult();

            BaselineCompilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new EmptyAnalyzer()));
            CompilationWithAnalyzers         = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new DoNotCreateTaskCompletionSourceWithWrongArguments()));
        }
Exemplo n.º 2
0
        public static void CreateEnvironmentCA2015()
        {
            var sources = new List <(string name, string content)>();

            for (var i = 0; i < Constants.Number_Of_Code_Files; i++)
            {
                var name = "TypeName" + i;
                sources.Add((name, @$ "
Imports System
Imports System.Buffers

Class {name}(Of T)
    Inherits MemoryManager(Of T)

    <Obsolete>
    Public Overrides Function GetSpan() As Span(Of T)
        Throw New NotImplementedException()
    End Function

    Public Overrides Function Pin(Optional elementIndex As Integer = 0) As MemoryHandle
        Throw New NotImplementedException()
    End Function

    Public Overrides Sub Unpin()
        Throw New NotImplementedException()
    End Sub

    Protected Overrides Sub Dispose(disposing As Boolean)
        Throw New NotImplementedException()
    End Sub

    Protected Overrides Sub Finalize()
    End Sub

End Class
"));
            }

            var compilation = VisualBasicCompilationHelper.CreateAsync(sources.ToArray()).GetAwaiter().GetResult();

            BaselineCompilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new EmptyAnalyzer()));
            CompilationWithAnalyzers         = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new DoNotDefineFinalizersForTypesDerivedFromMemoryManager()));
        }
        public static void CreateEnvironmentIL3001()
        {
            var sources = new List <(string name, string content)>();

            for (var i = 0; i < Constants.Number_Of_Code_Files; i++)
            {
                var name = "TypeName" + i;
                sources.Add((name, $@"Imports System
Imports System.Reflection

Class {name}
    Sub M()
        Dim a = Assembly.LoadFrom(""/some/path/not/in/bundle"")
        Dim b = a.GetFile(""/some/file/path"")
        Dim c = a.GetFiles()
    End Sub
End Class"));
            }

            var(compilation, options)        = VisualBasicCompilationHelper.CreateWithOptionsAsync(sources.ToArray(), new[] { ("build_property.PublishSingleFile", "true") }).GetAwaiter().GetResult();
Exemplo n.º 4
0
        public static void CreateEnvironmentIL3000()
        {
            var sources = new List <(string name, string content)>();

            for (var i = 0; i < Constants.Number_Of_Code_Files; i++)
            {
                var name = "TypeName" + i;
                sources.Add((name, @$ "
Imports System
Imports System.Reflection

Class {name}
    Sub M()
        Dim a = Assembly.GetExecutingAssembly()
        Dim b = a.Location
        Dim c = a.EscapedCodeBase
    End Sub
End Class"));
            }

            var(compilation, options)        = VisualBasicCompilationHelper.CreateWithOptionsAsync(sources.ToArray(), new[] { ("build_property.PublishSingleFile", "true") }).GetAwaiter().GetResult();
Exemplo n.º 5
0
        public static void CreateEnvironmentCA2013()
        {
            var sources = new List <(string name, string content)>();

            for (var i = 0; i < Constants.Number_Of_Code_Files; i++)
            {
                var name = "TypeName" + i;
                sources.Add((name, @$ "
Imports System

Class {name}
    Private Shared Function TestMethod(test As Integer, other As Object) As Boolean
        Return ReferenceEquals(test, other)
    End Function
End Class
"));
            }

            var compilation = VisualBasicCompilationHelper.CreateAsync(sources.ToArray()).GetAwaiter().GetResult();

            BaselineCompilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new EmptyAnalyzer()));
            CompilationWithAnalyzers         = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new DoNotUseReferenceEqualsWithValueTypesAnalyzer()));
        }
        public static void CreateEnvironmentCA2200()
        {
            var sources = new List <(string name, string content)>();

            for (var i = 0; i < Constants.Number_Of_Code_Files; i++)
            {
                var name = "TypeName" + i;
                sources.Add((name, @$ "
Class {name}
    Sub M()
        Try
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class
"));
            }

            var compilation = VisualBasicCompilationHelper.CreateAsync(sources.ToArray()).GetAwaiter().GetResult();

            BaselineCompilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new EmptyAnalyzer()));
            CompilationWithAnalyzers         = compilation.WithAnalyzers(ImmutableArray.Create <DiagnosticAnalyzer>(new RethrowToPreserveStackDetailsAnalyzer()));
        }