Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
#143: Handle expression body methods in implement clone method refact…
Browse files Browse the repository at this point in the history
…oring
  • Loading branch information
cezarypiatek committed Oct 31, 2020
1 parent 9e8da67 commit 8f447f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions MappingGenerator/.editorconfig
@@ -1,4 +1,4 @@
[*.cs]

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = error
# VSTHRD200: Use "Async" suffix for async methods
dotnet_diagnostic.VSTHRD200.severity = none
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.Formatting;
using System.Linq;
using MappingGenerator.Mappings.MappingImplementors;
using MappingGenerator.MethodHelpers;

namespace MappingGenerator.Features.Refactorings
{
Expand Down Expand Up @@ -48,7 +49,10 @@ private async Task<Document> ImplementCloneMethodBody(Document document, MethodD
var methodSymbol = semanticModel.GetDeclaredSymbol(methodDeclaration, cancellationToken: cancellationToken);
var mappingContext = new MappingContext(methodSymbol.ContainingType);
var cloneExpression = await CreateCloneExpressionAsync(generator, semanticModel, new AnnotatedType(methodSymbol.ReturnType), mappingContext).ConfigureAwait(false);
return await document.ReplaceNodes(methodDeclaration.Body, ((BaseMethodDeclarationSyntax) generator.MethodDeclaration(methodSymbol, cloneExpression)).Body, cancellationToken).ConfigureAwait(false);

var cloneBody = ((BaseMethodDeclarationSyntax) generator.MethodDeclaration(methodSymbol, cloneExpression)).Body;

return await document.ReplaceNodes(methodDeclaration, methodDeclaration.WithOnlyBody(cloneBody), cancellationToken).ConfigureAwait(false);
}

private bool IsCandidateForCloneMethod(MethodDeclarationSyntax md)
Expand All @@ -75,7 +79,7 @@ private async Task<Document> AddCloneImplementation(Document document, TypeDecla

if (newClassDeclaration.BaseList == null || newClassDeclaration.BaseList.Types.Any(x => x.Type.ToString().Contains("ICloneable")) == false)
{
var cloneableInterface = SyntaxFactory.ParseTypeName($"System.ICloneable");
var cloneableInterface = SyntaxFactory.ParseTypeName("System.ICloneable");
newClassDeclaration = generator.AddInterfaceType(newClassDeclaration, cloneableInterface.WithAdditionalAnnotations(Formatter.Annotation)) as TypeDeclarationSyntax;
}

Expand Down

0 comments on commit 8f447f5

Please sign in to comment.