Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (32 sloc) 1.63 KB
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Roslynator.CSharp.Syntax;
namespace Roslynator.CSharp.Refactorings
{
internal static class ReplaceHexadecimalLiteralWithDecimalLiteralRefactoring
{
public static void ComputeRefactoring(RefactoringContext context, LiteralExpressionSyntax literalExpression)
{
HexNumericLiteralExpressionInfo info = SyntaxInfo.HexNumericLiteralExpressionInfo(literalExpression);
if (!info.Success)
return;
LiteralExpressionSyntax newLiteralExpression = CSharpFactory.LiteralExpression(info.Value);
context.RegisterRefactoring(
$"Replace '{info.Text}' with '{newLiteralExpression}'",
cancellationToken => RefactorAsync(context.Document, literalExpression, newLiteralExpression, cancellationToken),
RefactoringIdentifiers.ReplaceHexadecimalLiteralWithDecimalLiteral);
}
private static Task<Document> RefactorAsync(
Document document,
LiteralExpressionSyntax literalExpression,
LiteralExpressionSyntax newLiteralExpression,
CancellationToken cancellationToken)
{
newLiteralExpression = newLiteralExpression.WithTriviaFrom(literalExpression);
return document.ReplaceNodeAsync(literalExpression, newLiteralExpression, cancellationToken);
}
}
}
You can’t perform that action at this time.