Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Add Move Static Member To Existing Type (#61519)"" #62284

Merged
merged 1 commit into from
Jun 30, 2022
Merged
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.MoveStaticMembers;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.Test.Utilities.MoveStaticMembers
{
Expand All @@ -20,23 +23,31 @@ public TestMoveStaticMembersService()
{
}

public string? DestinationType { get; set; }
public string? DestinationName { get; set; }

public ImmutableArray<string> SelectedMembers { get; set; }

public string? Filename { get; set; }

public bool CreateNew { get; set; } = true;

public MoveStaticMembersOptions GetMoveMembersToTypeOptions(Document document, INamedTypeSymbol selectedType, ISymbol? selectedNodeSymbol)
{
var selectedMembers = selectedType.GetMembers().WhereAsArray(symbol => SelectedMembers.Contains(symbol.Name));
var namespaceDisplay = selectedType.ContainingNamespace.IsGlobalNamespace
? string.Empty
: selectedType.ContainingNamespace.ToDisplayString();
// just return all the selected members
return new MoveStaticMembersOptions(
Filename!,
string.Join(".", namespaceDisplay, DestinationType!),
selectedMembers);
if (CreateNew)
{
var namespaceDisplay = selectedType.ContainingNamespace.IsGlobalNamespace
? string.Empty
: selectedType.ContainingNamespace.ToDisplayString();
// just return all the selected members
return new MoveStaticMembersOptions(
Filename!,
string.Join(".", namespaceDisplay, DestinationName!),
selectedMembers);
}

var destination = selectedType.ContainingNamespace.GetAllTypes(CancellationToken.None).First(t => t.ToDisplayString() == DestinationName);
return new MoveStaticMembersOptions(destination, selectedMembers);
}
}
}
Loading