JetBrains / JetBrains/resharper-devguide

Renaming refactoring question

Open
#21 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
74
Forks
36
PR merge metrics
No merged PRs in 30d

Description

Hello, Matt!

Please add some info about implementing renaming refactoring. And if you have some time please help me :)

For example I have enum declaration:

``` csharp
public enum MyCustomValues
{
Foo,
Bar
}
```

And I need to rename this enum. I try to use **CSharpSpecificElementsRenamesFactory**, but I don't realize how to do it right:

``` csharp
public class UseSingularNameInEnumsUnlessAreFlagsRemoveSSuffix : IBulbAction
{
private readonly IEnumDeclaration _declaration;

public UseSingularNameInEnumsUnlessAreFlagsRemoveSSuffix(IEnumDeclaration declaration)
{
_declaration = declaration;
}

public void Execute(ISolution solution, ITextControl textControl)
{
if (!_declaration.IsValid() || _declaration.DeclaredElement == null) return;

CSharpElementFactory elementFactory = CSharpElementFactory.GetInstance(_declaration.GetPsiModule());

var renameFactory = new CSharpSpecificElementsRenamesFactory();
if (!renameFactory.IsApplicable(_declaration.DeclaredElement))
return; // why previous enum declaration is not applicable and thus return

_declaration.GetPsiServices().Transactions.Execute(GetType().Name, () =>
{
using (solution.GetComponent().UsingWriteLock())
{
// is it right?
IEnumerable ranames = renameFactory.CreateAtomicRenames(_declaration.DeclaredElement, "NewClsName", true);
foreach (AtomicRenameBase rename in ranames)
{

}
}
});

// TODO: throw new System.NotImplementedException();
}

public string Text { get {return "Remove -s suffix."; } }
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.