Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;

namespace D2L.CodeStyle.Analyzers.Async.Generator;

Expand Down Expand Up @@ -111,7 +110,7 @@ private TypeSyntax TransformType( TypeSyntax typeSynt, bool isReturnType = false
return typeSynt;
}

if( returnTypeInfo.Type.ContainingNamespace.ToString() == "System.Threading.Tasks" ) {
if( returnTypeInfo.Type.ContainingNamespace?.ToString() == "System.Threading.Tasks" ) {
switch( returnTypeInfo.Type.MetadataName ) {
case "Task":
if( isReturnType ) {
Expand All @@ -134,7 +133,7 @@ private TypeSyntax TransformType( TypeSyntax typeSynt, bool isReturnType = false
);
return typeSynt;
}
} else if( returnTypeInfo.Type.MetadataName == "IAsyncEnumerable`1" && returnTypeInfo.Type.ContainingNamespace.ToString() == "System.Collections.Generic" ) {
} else if( returnTypeInfo.Type.MetadataName == "IAsyncEnumerable`1" && returnTypeInfo.Type.ContainingNamespace?.ToString() == "System.Collections.Generic" ) {
return ( (GenericNameSyntax)typeSynt )
.WithIdentifier( SyntaxFactory.Identifier( "IEnumerable" ) )
.WithTriviaFrom( typeSynt );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,56 @@ partial class Bar {
);
}

[Test]
public void OneFileWithOneMethodThatHasObjectArray() {
var result = RunGenerator( @"
using System;
using System.IO;
using System.Threading.Tasks;
using D2L.CodeStyle.Annotations;

namespace Foo;

sealed class Bar {
public void Baz() => Console.WriteLine( ""hello"" );

[GenerateSync]
public async Task BazAsync( StreamWriter x ) {
Object[] searchThings = null;
return;

}

public int Add( int x, int y ) => x + y;
}"


);

AssertNewTrees( result, @"#pragma warning disable CS1572
#nullable enable annotations

using System;
using System.IO;
using System.Threading.Tasks;
using D2L.CodeStyle.Annotations;

namespace Foo;

partial class Bar {

[Blocking]
public void Baz( StreamWriter x ) {
Object[] searchThings = null;
return;

}
}"


);
}

[Test]
public void InterfaceMethod() {
var result = RunGenerator( @"
Expand Down Expand Up @@ -175,6 +225,7 @@ public void Bar() {}
);
}


public (Compilation Before, Compilation After) RunGenerator( params string[] sources ) {
var oldCompilation = AsyncToSyncMethodTransformerTests.CreateSyncGeneratorTestCompilation(
sources.Select( src => CSharpSyntaxTree.ParseText( src ) ).ToArray()
Expand Down
Loading