├── .gitignore
├── AdjustNamespace.2022
├── AdjustNamespace.2022.csproj
├── Monikers.imagemanifest
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ ├── order16.png
│ ├── order512.png
│ └── order90.png
├── VSCommandTable.cs
├── VSCommandTable.vsct
├── source.extension.cs
└── source.extension.vsixmanifest
├── AdjustNamespace.VsixShared
├── AdjustNamespace.VsixShared.projitems
├── AdjustNamespace.VsixShared.shproj
├── AdjustNamespacePackage.cs
├── Adjusting
│ ├── Adjuster
│ │ ├── AdjusterFactory.cs
│ │ ├── Cs
│ │ │ └── RefProcessor.cs
│ │ ├── CsAdjuster.cs
│ │ ├── IAdjuster.cs
│ │ └── XamlAdjuster.cs
│ ├── Cleanup.cs
│ └── Fixer
│ │ ├── FixerContainer.cs
│ │ ├── FixerSet.cs
│ │ ├── IFixer.cs
│ │ └── Specific
│ │ ├── AddUsingFixer.cs
│ │ ├── NamespaceFixer.cs
│ │ └── QualifiedNameFixer.cs
├── Command
│ ├── AdjustNamespaceCommand.cs
│ ├── AdjustSelectedCommand.cs
│ ├── AdjustSolutionCommand.cs
│ └── EditSkippedPathsCommand.cs
├── Helper
│ ├── BaseViewModel.cs
│ ├── ChainViewModel.cs
│ ├── DocumentChangerHelper.cs
│ ├── HashSetHelper.cs
│ ├── ListHelper.cs
│ ├── NameHelper.cs
│ ├── NamespaceHelper.cs
│ ├── RoslynHelper.cs
│ ├── SolutionHelper.cs
│ ├── WorkspaceHelper.cs
│ └── WpfHelper.cs
├── ImageMonikers.cs
├── LICENSE.txt
├── Logging.cs
├── Namespace
│ ├── NamespaceCenter.cs
│ ├── NamespaceTransition.cs
│ └── NamespaceTransitionContainer.cs
├── Options
│ └── General.cs
├── Predicate.cs
├── RelayCommand.cs
├── Settings
│ ├── AdjustNamespaceSettings.cs
│ ├── AdjustNamespaceSettings2.cs
│ └── SettingsReader.cs
├── TypeContainer.cs
├── UI
│ ├── Control
│ │ ├── PerformingUserControl.xaml
│ │ ├── PerformingUserControl.xaml.cs
│ │ ├── PreparationUserControl.xaml
│ │ ├── PreparationUserControl.xaml.cs
│ │ ├── SelectedUserControl.xaml
│ │ ├── SelectedUserControl.xaml.cs
│ │ └── SpaceKeyUpEventTrigger.cs
│ ├── FileEx.cs
│ ├── StepFactory
│ │ ├── IStepFactory.cs
│ │ ├── PerformingStepFactory.cs
│ │ ├── PreparationStepFactory.cs
│ │ └── SelectedStepFactory.cs
│ ├── Theme.cs
│ └── ViewModel
│ │ ├── PerformingParameters.cs
│ │ ├── PerformingViewModel.cs
│ │ ├── PreparationStepViewModel.cs
│ │ ├── Select
│ │ ├── ISelectItemViewModel.cs
│ │ ├── SelectFileViewModel.cs
│ │ ├── SelectFolderViewModel.cs
│ │ └── SelectedStepViewModel.cs
│ │ └── SelectedStepParameters.cs
├── VsServices.cs
├── Window
│ ├── AdjustNamespaceWindow.xaml
│ ├── AdjustNamespaceWindow.xaml.cs
│ ├── EditSkippedPathsWindow.xaml
│ └── EditSkippedPathsWindow.xaml.cs
└── Xaml
│ ├── BodyProvider
│ ├── ClosedXamlBodyProvider.cs
│ ├── IXamlBodyProvider.cs
│ └── OpenedXamlBodyProvider.cs
│ ├── Positioned
│ ├── IXamlPerformable.cs
│ ├── IXamlPositioned.cs
│ ├── XamlAttributeReference.cs
│ ├── XamlClass.cs
│ ├── XamlControl.cs
│ ├── XamlX.cs
│ └── XamlXmlns.cs
│ ├── XamlDocument.cs
│ ├── XamlEngine.cs
│ └── XamlStructure.cs
├── AdjustNamespace.sln
├── LICENSE
├── README.md
├── Tests
└── Standard
│ ├── DatabaseProject
│ ├── ClassFile1.cs
│ ├── DatabaseProject.sqlproj
│ └── MyFolder
│ │ └── ClassFile2.cs
│ ├── TestMauiApp
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AppShell.xaml
│ ├── AppShell.xaml.cs
│ ├── MainPage.xaml
│ ├── MainPage.xaml.cs
│ ├── MauiProgram.cs
│ ├── Platforms
│ │ ├── Android
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── MainActivity.cs
│ │ │ ├── MainApplication.cs
│ │ │ └── Resources
│ │ │ │ └── values
│ │ │ │ └── colors.xml
│ │ ├── MacCatalyst
│ │ │ ├── AppDelegate.cs
│ │ │ ├── Info.plist
│ │ │ └── Program.cs
│ │ ├── Tizen
│ │ │ ├── Main.cs
│ │ │ └── tizen-manifest.xml
│ │ ├── Windows
│ │ │ ├── App.xaml
│ │ │ ├── App.xaml.cs
│ │ │ ├── Package.appxmanifest
│ │ │ └── app.manifest
│ │ └── iOS
│ │ │ ├── AppDelegate.cs
│ │ │ ├── Info.plist
│ │ │ └── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Resources
│ │ ├── AppIcon
│ │ │ ├── appicon.svg
│ │ │ └── appiconfg.svg
│ │ ├── Fonts
│ │ │ ├── OpenSans-Regular.ttf
│ │ │ └── OpenSans-Semibold.ttf
│ │ ├── Images
│ │ │ └── dotnet_bot.svg
│ │ ├── Raw
│ │ │ └── AboutAssets.txt
│ │ ├── Splash
│ │ │ └── splash.svg
│ │ └── Styles
│ │ │ ├── Colors.xaml
│ │ │ └── Styles.xaml
│ └── TestMauiApp.csproj
│ ├── TestProject
│ ├── A
│ │ └── B
│ │ │ └── C
│ │ │ └── D
│ │ │ └── Class1.cs
│ ├── Exp1
│ │ ├── Class123.cs
│ │ ├── Class4.cs
│ │ ├── Class5.cs
│ │ └── Class67.cs
│ ├── Exp10
│ │ ├── MyClass.cs
│ │ ├── Nested.cs
│ │ └── Typed.cs
│ ├── Exp11
│ │ ├── Folder1
│ │ │ └── Nested.cs
│ │ └── Folder2
│ │ │ ├── MyClass12.cs
│ │ │ └── Typed12.cs
│ ├── Exp12
│ │ ├── Class1
│ │ │ └── Class1.cs
│ │ └── Class2.cs
│ ├── Exp13
│ │ ├── Class1.cs
│ │ └── Exp13
│ │ │ └── Exp13.cs
│ ├── Exp2
│ │ ├── Class1.cs
│ │ └── Class2.cs
│ ├── Exp3
│ │ ├── Class1.cs
│ │ └── Class23456.cs
│ ├── Exp4
│ │ ├── Class1.cs
│ │ └── Class23.cs
│ ├── Exp5
│ │ ├── Class1.cs
│ │ ├── UserControl1.xaml
│ │ ├── UserControl1.xaml.cs
│ │ ├── UserControl2.xaml
│ │ ├── UserControl2.xaml.cs
│ │ ├── UserControl3.xaml
│ │ ├── UserControl3.xaml.cs
│ │ ├── UserControl4.xaml
│ │ ├── UserControl4.xaml.cs
│ │ ├── UserControl5.xaml
│ │ ├── UserControl5.xaml.cs
│ │ ├── UserControl6.xaml
│ │ └── UserControl6.xaml.cs
│ ├── Exp6
│ │ ├── Class1234.cs
│ │ └── Class5.cs
│ ├── Exp7
│ │ └── Class1.cs
│ ├── Exp8
│ │ └── FakeAttribute.cs
│ ├── Exp9
│ │ └── Class100.cs
│ ├── Program.cs
│ └── TestProject.csproj
│ ├── TestSharedProject
│ ├── SharedClass1.cs
│ ├── SharedFolder
│ │ └── SharedClass2.cs
│ ├── TestSharedProject.projitems
│ └── TestSharedProject.shproj
│ ├── TestSolution.sln
│ └── adjust_namespaces_settings.xml
├── demo1.png
├── demo2.png
└── demo3.png
/AdjustNamespace.2022/Monikers.imagemanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/AdjustNamespace.2022/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle(Vsix.Name)]
6 | [assembly: AssemblyDescription(Vsix.Description)]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany(Vsix.Author)]
9 | [assembly: AssemblyProduct(Vsix.Name)]
10 | [assembly: AssemblyCopyright(Vsix.Author)]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: AssemblyVersion(Vsix.Version)]
17 | [assembly: AssemblyFileVersion(Vsix.Version)]
18 |
19 | [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Xaml.Behaviors.dll")]
20 |
21 | namespace System.Runtime.CompilerServices
22 | {
23 | public class IsExternalInit { }
24 | }
--------------------------------------------------------------------------------
/AdjustNamespace.2022/Resources/order16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/AdjustNamespace.2022/Resources/order16.png
--------------------------------------------------------------------------------
/AdjustNamespace.2022/Resources/order512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/AdjustNamespace.2022/Resources/order512.png
--------------------------------------------------------------------------------
/AdjustNamespace.2022/Resources/order90.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/AdjustNamespace.2022/Resources/order90.png
--------------------------------------------------------------------------------
/AdjustNamespace.2022/VSCommandTable.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace AdjustNamespace
7 | {
8 | using System;
9 |
10 | ///
11 | /// Helper class that exposes all GUIDs used across VS Package.
12 | ///
13 | internal sealed partial class PackageGuids
14 | {
15 | public const string guidAdjustNamespacePackageString = "19967834-2536-4a51-82f7-e607434734d2";
16 | public static Guid guidAdjustNamespacePackage = new Guid(guidAdjustNamespacePackageString);
17 |
18 | public const string guidAdjustNamespacePackageCmdSetString = "3f7538ed-5c20-4d49-89fc-c401bb76df25";
19 | public static Guid guidAdjustNamespacePackageCmdSet = new Guid(guidAdjustNamespacePackageCmdSetString);
20 |
21 | public const string guidImagesString = "6309e701-5f02-4bc7-8376-02ec55028dbf";
22 | public static Guid guidImages = new Guid(guidImagesString);
23 | }
24 | ///
25 | /// Helper class that encapsulates all CommandIDs uses across VS Package.
26 | ///
27 | internal sealed partial class PackageIds
28 | {
29 | public const int ContextMenuGroup = 0x1020;
30 | public const int ExtensionMenuGroup = 0x201D;
31 | public const int ExtensionSubMenuGroup = 0x201E;
32 | public const int ExtensionSubMenu = 0x201F;
33 | public const int ExtensionSubMenuGroupService = 0x2020;
34 | public const int DoAdjustCommandId = 0x0300;
35 | public const int AdjustSolutionCommandId = 0x0301;
36 | public const int AdjustSelectedCommandId = 0x0302;
37 | public const int EditSkippedPathsCommandId = 0x0322;
38 | public const int order16 = 0x0001;
39 | }
40 | }
--------------------------------------------------------------------------------
/AdjustNamespace.2022/VSCommandTable.vsct:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
18 |
21 |
22 |
25 |
28 |
31 |
34 |
37 |
38 |
39 |
40 |
46 |
47 |
48 |
49 |
50 |
57 |
58 |
65 |
66 |
73 |
74 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/AdjustNamespace.2022/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace AdjustNamespace
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "AdjustNamespace.5744262e-0521-4f72-a2d6-aa7d60d8ea96";
11 | public const string Name = "Adjust C# Namespaces 2022";
12 | public const string Description = @"Fix incorrect namespaces for a single file, folder, project or a whole solution and rules the resulting regressions in the code (including XAML), e.g. fixes the broken references. This extension works like Resharper `Adjust namespaces` function.";
13 | public const string Language = "en-US";
14 | public const string Version = "0.3.4";
15 | public const string Author = "lsoft";
16 | public const string Tags = "namespace fix C#";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/AdjustNamespace.2022/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Adjust C# Namespaces 2022
6 | Fix incorrect namespaces for a single file, folder, project or a whole solution and rules the resulting regressions in the code (including XAML), e.g. fixes the broken references. This extension works like Resharper `Adjust namespaces` function.
7 | https://github.com/lsoft/AdjustNamespace
8 | LICENSE.txt
9 | Resources\order90.png
10 | Resources\order90.png
11 | namespace fix C#
12 | true
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/AdjustNamespace.VsixShared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | b8f4de5d-eeff-4f14-9c3d-2a6ee41db482
5 | 14.0
6 | 9.0
7 | enable
8 | nullable;CS8766;CS8767
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/AdjustNamespacePackage.cs:
--------------------------------------------------------------------------------
1 | global using Community.VisualStudio.Toolkit;
2 | global using Microsoft.VisualStudio.Shell;
3 | global using System;
4 | global using Task = System.Threading.Tasks.Task;
5 | using AdjustNamespace.Command;
6 | using System.Runtime.InteropServices;
7 | using System.Threading;
8 |
9 | namespace AdjustNamespace
10 | {
11 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
12 | [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
13 | [ProvideMenuResource("Menus.ctmenu", 1)]
14 | [Guid(PackageGuids.guidAdjustNamespacePackageString)]
15 | [ProvideOptionPage(typeof(Options.OptionsProvider.GeneralOptions), "Adjust Namespaces", "General", 0, 0, true, SupportsProfiles = true)]
16 | public sealed class AdjustNamespacePackage : ToolkitPackage
17 | {
18 | protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress)
19 | {
20 | await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
21 |
22 | await AdjustNamespaceCommand.InitializeAsync(this);
23 | await AdjustSolutionCommand.InitializeAsync(this);
24 | await AdjustSelectedCommand.InitializeAsync(this);
25 | await EditSkippedPathsCommand.InitializeAsync(this);
26 |
27 | await this.RegisterCommandsAsync();
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Adjuster/AdjusterFactory.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 |
5 | namespace AdjustNamespace.Adjusting.Adjuster
6 | {
7 | public class AdjusterFactory
8 | {
9 | private readonly VsServices _vss;
10 | private readonly NamespaceReplaceRegex _replaceRegex;
11 | private readonly bool _openFilesToEnableUndo;
12 | private readonly NamespaceCenter _namespaceCenter;
13 | private readonly List _xamlFilePaths;
14 |
15 | public static async Task CreateAsync(
16 | VsServices vss,
17 | NamespaceReplaceRegex replaceRegex,
18 | bool openFilesToEnableUndo,
19 | NamespaceCenter namespaceCenter
20 | )
21 | {
22 | if (replaceRegex is null)
23 | {
24 | throw new ArgumentNullException(nameof(replaceRegex));
25 | }
26 |
27 | if (namespaceCenter is null)
28 | {
29 | throw new ArgumentNullException(nameof(namespaceCenter));
30 | }
31 |
32 | //get all xaml files in current solution
33 | var filePaths = await SolutionHelper.GetAllFilesFromAsync();
34 | var xamlFilePaths = filePaths.FindAll(fp => fp.EndsWith(".xaml"));
35 |
36 | return new AdjusterFactory(
37 | vss,
38 | replaceRegex,
39 | openFilesToEnableUndo,
40 | namespaceCenter,
41 | xamlFilePaths
42 | );
43 |
44 | }
45 |
46 | private AdjusterFactory(
47 | VsServices vss,
48 | NamespaceReplaceRegex replaceRegex,
49 | bool openFilesToEnableUndo,
50 | NamespaceCenter namespaceCenter,
51 | List xamlFilePaths
52 | )
53 | {
54 | if (replaceRegex is null)
55 | {
56 | throw new ArgumentNullException(nameof(replaceRegex));
57 | }
58 |
59 | if (namespaceCenter is null)
60 | {
61 | throw new ArgumentNullException(nameof(namespaceCenter));
62 | }
63 |
64 | if (xamlFilePaths is null)
65 | {
66 | throw new ArgumentNullException(nameof(xamlFilePaths));
67 | }
68 |
69 | _vss = vss;
70 | _replaceRegex = replaceRegex;
71 | _openFilesToEnableUndo = openFilesToEnableUndo;
72 | _namespaceCenter = namespaceCenter;
73 | _xamlFilePaths = xamlFilePaths;
74 | }
75 |
76 | public async Task CreateAsync(
77 | string subjectFilePath
78 | )
79 | {
80 | if (subjectFilePath is null)
81 | {
82 | throw new ArgumentNullException(nameof(subjectFilePath));
83 | }
84 |
85 | var pii = await SolutionHelper.TryGetProjectItemAsync(subjectFilePath);
86 | if (!pii.HasValue)
87 | {
88 | return null;
89 | }
90 |
91 | var targetNamespace = await NamespaceHelper.TryDetermineTargetNamespaceAsync(
92 | pii.Value.Project,
93 | _vss,
94 | _replaceRegex,
95 | subjectFilePath
96 | );
97 | if (string.IsNullOrEmpty(targetNamespace))
98 | {
99 | return null;
100 | }
101 |
102 | if (subjectFilePath.EndsWith(".xaml"))
103 | {
104 | //it's a xaml
105 |
106 | var xamlAdjuster = new XamlAdjuster(
107 | _vss,
108 | _openFilesToEnableUndo,
109 | subjectFilePath,
110 | targetNamespace!
111 | );
112 | return xamlAdjuster;
113 | }
114 | else
115 | {
116 | //we can do nothing with not a C# documents
117 | var subjectDocument = _vss.Workspace.GetDocument(subjectFilePath);
118 | if (!subjectDocument.IsDocumentInScope())
119 | {
120 | return null;
121 | }
122 |
123 | var csAdjuster = new CsAdjuster(
124 | _vss,
125 | _openFilesToEnableUndo,
126 | _namespaceCenter,
127 | subjectFilePath,
128 | targetNamespace!,
129 | _xamlFilePaths
130 | );
131 |
132 | return csAdjuster;
133 | }
134 | }
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Adjuster/IAdjuster.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading.Tasks;
5 |
6 | namespace AdjustNamespace.Adjusting.Adjuster
7 | {
8 | public interface IAdjuster
9 | {
10 | Task AdjustAsync();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Adjuster/XamlAdjuster.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Adjusting.Adjuster;
2 | using AdjustNamespace.Xaml;
3 | using System;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 |
7 | namespace AdjustNamespace.Adjusting
8 | {
9 | ///
10 | /// Adjuster for xaml file.
11 | ///
12 | public class XamlAdjuster : IAdjuster
13 | {
14 | private readonly VsServices _vss;
15 | private readonly string _subjectFilePath;
16 | private readonly string _targetNamespace;
17 | private readonly bool _openFilesToEnableUndo;
18 |
19 | public XamlAdjuster(
20 | VsServices vss,
21 | bool openFilesToEnableUndo,
22 | string subjectFilePath,
23 | string targetNamespace
24 | )
25 | {
26 | if (subjectFilePath is null)
27 | {
28 | throw new ArgumentNullException(nameof(subjectFilePath));
29 | }
30 |
31 | if (targetNamespace is null)
32 | {
33 | throw new ArgumentNullException(nameof(targetNamespace));
34 | }
35 |
36 | _vss = vss;
37 | _openFilesToEnableUndo = openFilesToEnableUndo;
38 | _subjectFilePath = subjectFilePath;
39 | _targetNamespace = targetNamespace;
40 | }
41 |
42 | public async Task AdjustAsync()
43 | {
44 | var (xamlDocument, modifiedDocument) = await TryModifyDocumentAsync();
45 | if (!modifiedDocument.HasValue)
46 | {
47 | return false;
48 | }
49 |
50 | modifiedDocument.Value.SaveIfChangesExistsAgainst(xamlDocument);
51 |
52 | return true;
53 | }
54 |
55 | public async Task IsChangesExistsAsync(
56 | )
57 | {
58 | var (xamlDocument, modifiedDocument) = await TryModifyDocumentAsync();
59 | return modifiedDocument.HasValue && modifiedDocument.Value.IsChangesExists(xamlDocument);
60 | }
61 |
62 | private async Task<(XamlDocument, XamlDocument?)> TryModifyDocumentAsync(
63 | )
64 | {
65 | var xamlEngine = new XamlEngine(
66 | _vss
67 | );
68 |
69 | var xamlDocument = await xamlEngine.CreateDocumentAsync(
70 | _openFilesToEnableUndo,
71 | _subjectFilePath
72 | );
73 |
74 | if (!xamlDocument.GetRootInfo(out var rootNamespace, out var rootName))
75 | {
76 | return (xamlDocument, null);
77 | }
78 |
79 | if (rootNamespace == _targetNamespace)
80 | {
81 | return (xamlDocument, null);
82 | }
83 |
84 | var modifiedXamlDocument = xamlDocument.MoveObject(
85 | rootNamespace!,
86 | rootName!,
87 | _targetNamespace
88 | );
89 |
90 | return (xamlDocument, modifiedXamlDocument);
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Cleanup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using Microsoft.CodeAnalysis;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using AdjustNamespace.Helper;
8 | using System.Threading;
9 |
10 | namespace AdjustNamespace.Adjusting
11 | {
12 | public class Cleanup
13 | {
14 | private readonly VsServices _vss;
15 | private readonly NamespaceCenter _namespaceCenter;
16 |
17 | public Cleanup(
18 | VsServices vss,
19 | NamespaceCenter namespaceCenter
20 | )
21 | {
22 | if (namespaceCenter is null)
23 | {
24 | throw new ArgumentNullException(nameof(namespaceCenter));
25 | }
26 |
27 | _vss = vss;
28 | _namespaceCenter = namespaceCenter;
29 | }
30 |
31 | public async Task RemoveEmptyUsingStatementsForAsync(
32 | string documentFilePath
33 | )
34 | {
35 | var workspace = _vss.Workspace;
36 |
37 | bool r = true;
38 | do
39 | {
40 | var (document, syntaxRoot) = await workspace.GetDocumentAndSyntaxRootAsync(documentFilePath);
41 | if (document == null || syntaxRoot == null)
42 | {
43 | //something went wrong
44 | //skip this document
45 | return;
46 | }
47 |
48 | var namespaces = syntaxRoot.GetAllDescendants();
49 |
50 | var toRemove = _namespaceCenter.GetRemovedNamespaces(namespaces);
51 | if (toRemove.Count == 0)
52 | {
53 | continue;
54 | }
55 |
56 | syntaxRoot = syntaxRoot.RemoveNodes(toRemove, SyntaxRemoveOptions.KeepNoTrivia);
57 | if (syntaxRoot != null)
58 | {
59 | var changedDocument = document.WithSyntaxRoot(syntaxRoot);
60 |
61 | r = workspace.TryApplyChanges(changedDocument.Project.Solution);
62 | }
63 | }
64 | while (!r);
65 | }
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Fixer/FixerContainer.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Adjusting.Fixer;
2 | using AdjustNamespace.Adjusting;
3 | using Microsoft.VisualStudio.LanguageServices;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.VisualStudio.Language.CodeCleanUp;
9 | using System.Diagnostics;
10 |
11 | namespace AdjustNamespace.Adjusting.Fixer
12 | {
13 | ///
14 | /// Container for all fixers we produce.
15 | ///
16 | public class FixerContainer
17 | {
18 | private readonly VsServices _vss;
19 | private readonly bool _openFilesToEnableUndo;
20 |
21 | private readonly Dictionary _dict = new();
22 |
23 | public FixerContainer(
24 | VsServices vss,
25 | bool openFilesToEnableUndo
26 | )
27 | {
28 | _vss = vss;
29 | _openFilesToEnableUndo = openFilesToEnableUndo;
30 | }
31 |
32 | public T Fixer(string filePath)
33 | where T : IFixer
34 | {
35 | if (!_dict.TryGetValue(filePath, out var fixerSet))
36 | {
37 | fixerSet = AddFixersFor(filePath);
38 | }
39 |
40 | return fixerSet.Fixer();
41 | }
42 |
43 | public async Task FixAllAsync()
44 | {
45 | foreach (var pair in _dict)
46 | {
47 | var targetFilePath = pair.Key;
48 |
49 | Debug.WriteLine($"Fix references in {targetFilePath}");
50 |
51 | await pair.Value.FixAllAsync();
52 | }
53 | }
54 |
55 | private FixerSet AddFixersFor(string filePath)
56 | {
57 | var fs = new FixerSet(_vss, _openFilesToEnableUndo, filePath);
58 | _dict[filePath] = fs;
59 | return fs;
60 | }
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Fixer/FixerSet.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Adjusting.Fixer.Specific;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace AdjustNamespace.Adjusting.Fixer
7 | {
8 | ///
9 | /// All fixer for specific file.
10 | ///
11 | public readonly struct FixerSet
12 | {
13 | private readonly VsServices _vss;
14 | private readonly bool _openFilesToEnableUndo;
15 |
16 | public readonly string FilePath;
17 |
18 | private readonly List _fixers;
19 |
20 | public FixerSet(
21 | VsServices vss,
22 | bool openFilesToEnableUndo,
23 | string filePath
24 | )
25 | {
26 | if (filePath is null)
27 | {
28 | throw new ArgumentNullException(nameof(filePath));
29 | }
30 |
31 | _vss = vss;
32 | _openFilesToEnableUndo = openFilesToEnableUndo;
33 | FilePath = filePath;
34 |
35 | _fixers = new List
36 | {
37 | new QualifiedNameFixer(vss.Workspace, filePath),
38 | new AddUsingFixer(vss.Workspace, filePath),
39 | new NamespaceFixer(vss, filePath),
40 | };
41 | }
42 |
43 | public T Fixer()
44 | where T : IFixer
45 | {
46 | var result = _fixers.FirstOrDefault(f => f is T);
47 | if (result == null)
48 | {
49 | throw new InvalidOperationException($"Unknown fixer {typeof(T).FullName}");
50 | }
51 |
52 | return (T)result;
53 | }
54 |
55 | internal async System.Threading.Tasks.Task FixAllAsync()
56 | {
57 | if (_openFilesToEnableUndo)
58 | {
59 | await _vss.OpenFileAsync(FilePath);
60 | }
61 |
62 | foreach (var fixer in _fixers)
63 | {
64 | await fixer.FixAsync();
65 | }
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Fixer/IFixer.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace AdjustNamespace.Adjusting.Fixer
4 | {
5 | public interface IFixer
6 | {
7 | public string FilePath
8 | {
9 | get;
10 | }
11 |
12 | Task FixAsync();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Fixer/Specific/AddUsingFixer.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.CSharp;
4 | using Microsoft.CodeAnalysis.CSharp.Syntax;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Diagnostics;
8 | using System.Linq;
9 | using System.Threading.Tasks;
10 |
11 | namespace AdjustNamespace.Adjusting.Fixer
12 | {
13 | ///
14 | /// Fixer for adding a using statements like using System.Threading.Tasks
15 | ///
16 | public class AddUsingFixer : IFixer
17 | {
18 | private readonly Workspace _workspace;
19 | private readonly HashSet _symbolTargetNamespaces = new ();
20 |
21 | public string FilePath
22 | {
23 | get;
24 | }
25 |
26 | public AddUsingFixer(
27 | Workspace workspace,
28 | string filePath
29 | )
30 | {
31 | if (workspace is null)
32 | {
33 | throw new ArgumentNullException(nameof(workspace));
34 | }
35 |
36 | if (filePath is null)
37 | {
38 | throw new ArgumentNullException(nameof(filePath));
39 | }
40 |
41 | _workspace = workspace;
42 | FilePath = filePath;
43 | }
44 |
45 |
46 | public void AddSubject(string symbolTargetNamespace)
47 | {
48 | if (symbolTargetNamespace is null)
49 | {
50 | throw new ArgumentNullException(nameof(symbolTargetNamespace));
51 | }
52 |
53 | _symbolTargetNamespaces.Add(symbolTargetNamespace);
54 | }
55 |
56 |
57 | public async Task FixAsync()
58 | {
59 | bool r;
60 | do
61 | {
62 | var (document, syntaxRoot) = await _workspace.GetDocumentAndSyntaxRootAsync(FilePath);
63 | if (document == null || syntaxRoot == null)
64 | {
65 | //skip this document
66 | return;
67 | }
68 |
69 | foreach (var symbolTargetNamespace in _symbolTargetNamespaces)
70 | {
71 | var usingSyntaxes = syntaxRoot
72 | .DescendantNodes()
73 | .OfType()
74 | .ToList();
75 |
76 | if (usingSyntaxes.Count > 0)
77 | {
78 | if (usingSyntaxes.Any(s => s.Name.ToString() == symbolTargetNamespace))
79 | {
80 | //that using already exists
81 | continue;
82 | }
83 | }
84 |
85 | Debug.WriteLine($"Fix references in {FilePath}: Add '{symbolTargetNamespace}' ");
86 |
87 | if (usingSyntaxes.Count > 0)
88 | {
89 | var lastUsing = usingSyntaxes.Last();
90 |
91 | syntaxRoot = syntaxRoot.InsertNodesAfter(
92 | lastUsing,
93 | new[]
94 | {
95 | SyntaxFactory.UsingDirective(
96 | SyntaxFactory.ParseName(
97 | " " + symbolTargetNamespace
98 | )
99 | ).WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed)
100 | .WithLeadingTrivia(lastUsing.GetLeadingTrivia())
101 | });
102 | }
103 | else
104 | {
105 | var cus = (CompilationUnitSyntax)syntaxRoot;
106 | var modifiedcus = cus.AddUsings(
107 | SyntaxFactory.UsingDirective(
108 | SyntaxFactory.ParseName(
109 | " " + symbolTargetNamespace
110 | )
111 | ).WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed, SyntaxFactory.CarriageReturnLineFeed)
112 | .WithLeadingTrivia(cus.GetLeadingTrivia())
113 | );
114 |
115 | syntaxRoot = modifiedcus;
116 | }
117 | }
118 |
119 | var changedDocument = document.WithSyntaxRoot(syntaxRoot);
120 | r = _workspace.TryApplyChanges(changedDocument.Project.Solution);
121 | }
122 | while (!r);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Fixer/Specific/NamespaceFixer.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using AdjustNamespace.Helper;
8 | using System.Linq;
9 | using Microsoft.CodeAnalysis;
10 | using AdjustNamespace.Namespace;
11 |
12 | namespace AdjustNamespace.Adjusting.Fixer.Specific
13 | {
14 | ///
15 | /// A fixer for editing namespace clauses to the correct one.
16 | ///
17 | public class NamespaceFixer : IFixer
18 | {
19 | private readonly VsServices _vss;
20 | private readonly List _subjectList = new();
21 |
22 | public string FilePath
23 | {
24 | get;
25 | }
26 |
27 | public NamespaceFixer(
28 | VsServices vss,
29 | string filePath
30 | )
31 | {
32 | _vss = vss;
33 | FilePath = filePath;
34 | }
35 |
36 | public void AddSubject(NamespaceTransitionContainer ntc)
37 | {
38 | _subjectList.Add(ntc);
39 | }
40 |
41 | public async Task FixAsync()
42 | {
43 | var workspace = _vss.Workspace;
44 |
45 | foreach (var ntc in _subjectList)
46 | {
47 | foreach (var transition in ntc.Transitions.Where(ni => ni.IsRoot))
48 | {
49 | bool r = true;
50 | do
51 | {
52 | var (openedDocument, syntaxRoot) = await workspace.GetDocumentAndSyntaxRootAsync(FilePath);
53 | if (openedDocument == null || syntaxRoot == null)
54 | {
55 | //something went wrong
56 | //skip this document
57 | return;
58 | }
59 |
60 | if (!syntaxRoot.TryFindNamespaceNodesFor(transition.OriginalName, out var ufNamespaces))
61 | {
62 | //skip this namespace
63 | break;
64 | }
65 |
66 | var ufNamespace = ufNamespaces.First();
67 |
68 | //class A : IA {}
69 | //we're moving A into a different namespace, but IA are not.
70 | //we need to insert 'using old namespace'
71 | //otherwise ia will not be resolved
72 |
73 | //we can't determite it is the case or it's not without a costly analysis
74 | //it's a subject for a future work
75 | //so add at 100% cases now
76 |
77 | var cus = syntaxRoot as CompilationUnitSyntax;
78 | if (cus == null)
79 | {
80 | //skip this namespace
81 | break;
82 | }
83 | var newUsingStatement = SyntaxFactory.UsingDirective(
84 | SyntaxFactory.ParseName(
85 | " " + ufNamespace!.Name
86 | )
87 | ).WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed);
88 |
89 | cus = cus.AddUsings(newUsingStatement);
90 |
91 | if (!cus.TryFindNamespaceNodesFor(transition.OriginalName, out var fNamespaces))
92 | {
93 | //skip this namespace
94 | break;
95 | }
96 |
97 | foreach (var fNamespace in fNamespaces!)
98 | {
99 | var newName = SyntaxFactory.ParseName(
100 | transition.ModifiedName
101 | );
102 |
103 | if (fNamespace is NamespaceDeclarationSyntax)
104 | {
105 | newName = newName
106 | .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed)
107 | ;
108 | }
109 |
110 | var fixedNamespace = fNamespace!.WithName(
111 | newName
112 | )
113 | .WithLeadingTrivia(fNamespace.GetLeadingTrivia())
114 | .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed)
115 | ;
116 |
117 | cus = cus!.ReplaceNode(
118 | fNamespace,
119 | fixedNamespace
120 | );
121 | }
122 |
123 | openedDocument = openedDocument.WithSyntaxRoot(cus!);
124 |
125 | r = workspace.TryApplyChanges(openedDocument.Project.Solution);
126 | }
127 | while (!r);
128 | }
129 | }
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Adjusting/Fixer/Specific/QualifiedNameFixer.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using Microsoft.CodeAnalysis.Text;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Threading.Tasks;
9 |
10 | namespace AdjustNamespace.Adjusting.Fixer
11 | {
12 | ///
13 | /// Fixer for fully qualified names like AdjustNamespace.Adjusting.Fixer.QualifiedNameFixer
14 | ///
15 | public class QualifiedNameFixer : IFixer
16 | {
17 | private readonly Workspace _workspace;
18 | private readonly List _arguments = new ();
19 |
20 | public string FilePath
21 | {
22 | get;
23 | }
24 |
25 | public QualifiedNameFixer(
26 | Workspace workspace,
27 | string filePath
28 | )
29 | {
30 | if (workspace is null)
31 | {
32 | throw new ArgumentNullException(nameof(workspace));
33 | }
34 |
35 | if (filePath is null)
36 | {
37 | throw new ArgumentNullException(nameof(filePath));
38 | }
39 |
40 | _workspace = workspace;
41 | FilePath = filePath;
42 | }
43 |
44 | public void AddSubject(QualifiedNameFixerArgument qnsa)
45 | {
46 | _arguments.Add(qnsa);
47 | }
48 |
49 | public async Task FixAsync()
50 | {
51 | await _workspace.ApplyModifiedDocumentAsync(
52 | FilePath,
53 | (document, syntaxRoot) =>
54 | {
55 | var nodesToBeReplaced = _arguments.ConvertAll(
56 | a => syntaxRoot.FindNode(a.SubjectNodeSpan).GoDownTo(a.ToReplaceSyntax.GetType())!
57 | );
58 |
59 | var mSyntaxRoot = syntaxRoot.ReplaceNodes(
60 | nodesToBeReplaced,
61 | (n0, n1) =>
62 | {
63 | var founda = _arguments.First(a => n0.Span == a.SubjectNodeSpan);
64 |
65 | return founda.ToReplaceSyntax;
66 | });
67 |
68 | var changedDocument = document.WithSyntaxRoot(mSyntaxRoot);
69 | return changedDocument;
70 | }
71 | );
72 | }
73 |
74 | public readonly struct QualifiedNameFixerArgument
75 | {
76 | public readonly TextSpan SubjectNodeSpan;
77 | public readonly SyntaxNode ToReplaceSyntax;
78 |
79 | public QualifiedNameFixerArgument(
80 | TextSpan subjectNodeSpan,
81 | SyntaxNode toReplaceSyntax
82 | )
83 | {
84 | if (toReplaceSyntax is null)
85 | {
86 | throw new ArgumentNullException(nameof(toReplaceSyntax));
87 | }
88 |
89 | SubjectNodeSpan = subjectNodeSpan;
90 | ToReplaceSyntax = toReplaceSyntax;
91 | }
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Command/AdjustSelectedCommand.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using AdjustNamespace.Window;
3 | using Microsoft.VisualStudio.Shell;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.ComponentModel.Design;
7 |
8 | namespace AdjustNamespace.Command
9 | {
10 | ///
11 | /// Command handler
12 | ///
13 | internal sealed class AdjustSelectedCommand
14 | {
15 | public static string ProjectKind = "{52AEFF70-BBD8-11d2-8598-006097C68E81}";
16 |
17 |
18 | ///
19 | /// Command ID.
20 | ///
21 | public const int CommandId = PackageIds.AdjustSelectedCommandId;
22 |
23 | ///
24 | /// Command menu group (command set GUID).
25 | ///
26 | public static readonly Guid CommandSet = new Guid("3f7538ed-5c20-4d49-89fc-c401bb76df25");
27 |
28 | ///
29 | /// VS Package that provides this command, not null.
30 | ///
31 | private readonly AsyncPackage package;
32 |
33 | ///
34 | /// Initializes a new instance of the class.
35 | /// Adds our command handlers for menu (commands must exist in the command table file)
36 | ///
37 | /// Owner package, not null.
38 | /// Command service to add command to, not null.
39 | private AdjustSelectedCommand(AsyncPackage package, OleMenuCommandService commandService)
40 | {
41 | this.package = package ?? throw new ArgumentNullException(nameof(package));
42 | commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
43 |
44 | var menuCommandID = new CommandID(CommandSet, CommandId);
45 | var menuItem = new MenuCommand(Execute, menuCommandID);
46 | commandService.AddCommand(menuItem);
47 | }
48 |
49 | ///
50 | /// Gets the instance of the command.
51 | ///
52 | public static AdjustSelectedCommand? Instance
53 | {
54 | get;
55 | private set;
56 | }
57 |
58 | ///
59 | /// Gets the service provider from the owner package.
60 | ///
61 | Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
62 | {
63 | get
64 | {
65 | return package;
66 | }
67 | }
68 |
69 | ///
70 | /// Initializes the singleton instance of the command.
71 | ///
72 | /// Owner package, not null.
73 | public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
74 | {
75 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
76 |
77 | var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
78 | Instance = new AdjustSelectedCommand(package, commandService!);
79 | }
80 |
81 | ///
82 | /// This function is the callback used to execute the command when the menu item is clicked.
83 | /// See the constructor to see how the menu item is associated with this function using
84 | /// OleMenuCommandService service and MenuCommand class.
85 | ///
86 | /// Event sender.
87 | /// Event args.
88 | private async void Execute(object sender, EventArgs e)
89 | {
90 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
91 |
92 | try
93 | {
94 | var vss = await VsServices.CreateAsync(ServiceProvider);
95 |
96 | //HashSet is needed to remove duplicates paths
97 | //this is possible if you click Adjust on xaml file (with cs behind)
98 | var filePaths = new HashSet();
99 |
100 | var sew = await VS.Windows.GetSolutionExplorerWindowAsync();
101 | if (sew != null)
102 | {
103 | var selection = await sew.GetSelectionAsync();
104 |
105 | foreach (var item in selection)
106 | {
107 | var files = await item.ProcessDownRecursivelyForAsync(SolutionItemType.PhysicalFile, null);
108 | filePaths.AddRange(
109 | files.ConvertAll(i => i.FullPath!).FindAll(i => !string.IsNullOrEmpty(i))
110 | );
111 | }
112 | }
113 |
114 | if (filePaths.Count > 0)
115 | {
116 | var window = AdjustNamespaceWindow.Create(vss, filePaths);
117 | window.ShowModal();
118 | }
119 | }
120 | catch (Exception excp)
121 | {
122 | Logging.LogVS(excp);
123 | }
124 | }
125 |
126 |
127 | //private void ShowError(string errorMessage)
128 | //{
129 | // VsShellUtilities.ShowMessageBox(
130 | // package,
131 | // errorMessage,
132 | // $"Error has been found",
133 | // OLEMSGICON.OLEMSGICON_WARNING,
134 | // OLEMSGBUTTON.OLEMSGBUTTON_OK,
135 | // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
136 | // );
137 | //}
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Command/AdjustSolutionCommand.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using AdjustNamespace.Window;
3 | using Microsoft.VisualStudio.Shell;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.ComponentModel.Design;
7 |
8 | namespace AdjustNamespace.Command
9 | {
10 | ///
11 | /// Command handler
12 | ///
13 | internal sealed class AdjustSolutionCommand
14 | {
15 | public static string ProjectKind = "{52AEFF70-BBD8-11d2-8598-006097C68E81}";
16 |
17 |
18 | ///
19 | /// Command ID.
20 | ///
21 | public const int CommandId = PackageIds.AdjustSolutionCommandId;
22 |
23 | ///
24 | /// Command menu group (command set GUID).
25 | ///
26 | public static readonly Guid CommandSet = new Guid("3f7538ed-5c20-4d49-89fc-c401bb76df25");
27 |
28 | ///
29 | /// VS Package that provides this command, not null.
30 | ///
31 | private readonly AsyncPackage package;
32 |
33 | ///
34 | /// Initializes a new instance of the class.
35 | /// Adds our command handlers for menu (commands must exist in the command table file)
36 | ///
37 | /// Owner package, not null.
38 | /// Command service to add command to, not null.
39 | private AdjustSolutionCommand(AsyncPackage package, OleMenuCommandService commandService)
40 | {
41 | this.package = package ?? throw new ArgumentNullException(nameof(package));
42 | commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
43 |
44 | var menuCommandID = new CommandID(CommandSet, CommandId);
45 | var menuItem = new MenuCommand(Execute, menuCommandID);
46 | commandService.AddCommand(menuItem);
47 | }
48 |
49 | ///
50 | /// Gets the instance of the command.
51 | ///
52 | public static AdjustSolutionCommand? Instance
53 | {
54 | get;
55 | private set;
56 | }
57 |
58 | ///
59 | /// Gets the service provider from the owner package.
60 | ///
61 | Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
62 | {
63 | get
64 | {
65 | return package;
66 | }
67 | }
68 |
69 | ///
70 | /// Initializes the singleton instance of the command.
71 | ///
72 | /// Owner package, not null.
73 | public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
74 | {
75 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
76 |
77 | var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
78 | Instance = new AdjustSolutionCommand(package, commandService!);
79 | }
80 |
81 | ///
82 | /// This function is the callback used to execute the command when the menu item is clicked.
83 | /// See the constructor to see how the menu item is associated with this function using
84 | /// OleMenuCommandService service and MenuCommand class.
85 | ///
86 | /// Event sender.
87 | /// Event args.
88 | private async void Execute(object sender, EventArgs e)
89 | {
90 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
91 |
92 | try
93 | {
94 | var vss = await VsServices.CreateAsync(ServiceProvider);
95 |
96 | //HashSet is needed to remove duplicates paths
97 | //this is possible if you click Adjust on xaml file (with cs behind)
98 | var filePaths = new HashSet(
99 | await SolutionHelper.GetAllFilesFromAsync()
100 | );
101 |
102 | if (filePaths.Count > 0)
103 | {
104 | var window = AdjustNamespaceWindow.Create(vss, filePaths);
105 | window.ShowModal();
106 | }
107 | }
108 | catch (Exception excp)
109 | {
110 | Logging.LogVS(excp);
111 | }
112 | }
113 |
114 |
115 | //private void ShowError(string errorMessage)
116 | //{
117 | // VsShellUtilities.ShowMessageBox(
118 | // package,
119 | // errorMessage,
120 | // $"Error has been found",
121 | // OLEMSGICON.OLEMSGICON_WARNING,
122 | // OLEMSGBUTTON.OLEMSGBUTTON_OK,
123 | // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
124 | // );
125 | //}
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Command/EditSkippedPathsCommand.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Window;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.ComponentModel.Design;
5 |
6 | namespace AdjustNamespace.Command
7 | {
8 | ///
9 | /// Command handler
10 | ///
11 | internal sealed class EditSkippedPathsCommand
12 | {
13 | public static string ProjectKind = "{52AEFF70-BBD8-11d2-8598-006097C68E81}";
14 |
15 |
16 | ///
17 | /// Command ID.
18 | ///
19 | public const int CommandId = PackageIds.EditSkippedPathsCommandId;
20 |
21 | ///
22 | /// Command menu group (command set GUID).
23 | ///
24 | public static readonly Guid CommandSet = new Guid("3f7538ed-5c20-4d49-89fc-c401bb76df25");
25 |
26 | ///
27 | /// VS Package that provides this command, not null.
28 | ///
29 | private readonly AsyncPackage package;
30 |
31 | ///
32 | /// Initializes a new instance of the class.
33 | /// Adds our command handlers for menu (commands must exist in the command table file)
34 | ///
35 | /// Owner package, not null.
36 | /// Command service to add command to, not null.
37 | private EditSkippedPathsCommand(AsyncPackage package, OleMenuCommandService commandService)
38 | {
39 | this.package = package ?? throw new ArgumentNullException(nameof(package));
40 | commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
41 |
42 | var menuCommandID = new CommandID(CommandSet, CommandId);
43 | var menuItem = new MenuCommand(Execute, menuCommandID);
44 | commandService.AddCommand(menuItem);
45 | }
46 |
47 | ///
48 | /// Gets the instance of the command.
49 | ///
50 | public static EditSkippedPathsCommand? Instance
51 | {
52 | get;
53 | private set;
54 | }
55 |
56 | ///
57 | /// Gets the service provider from the owner package.
58 | ///
59 | Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
60 | {
61 | get
62 | {
63 | return package;
64 | }
65 | }
66 |
67 | ///
68 | /// Initializes the singleton instance of the command.
69 | ///
70 | /// Owner package, not null.
71 | public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
72 | {
73 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
74 |
75 | var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
76 | Instance = new EditSkippedPathsCommand(package, commandService!);
77 | }
78 |
79 | ///
80 | /// This function is the callback used to execute the command when the menu item is clicked.
81 | /// See the constructor to see how the menu item is associated with this function using
82 | /// OleMenuCommandService service and MenuCommand class.
83 | ///
84 | /// Event sender.
85 | /// Event args.
86 | private async void Execute(object sender, EventArgs e)
87 | {
88 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
89 |
90 | try
91 | {
92 | var vss = await VsServices.CreateAsync(ServiceProvider);
93 |
94 | var w = new EditSkippedPathsWindow(
95 | vss
96 | );
97 | w.ShowDialog();
98 | }
99 | catch (Exception excp)
100 | {
101 | Logging.LogVS(excp);
102 | }
103 | }
104 |
105 |
106 | //private void ShowError(string errorMessage)
107 | //{
108 | // VsShellUtilities.ShowMessageBox(
109 | // package,
110 | // errorMessage,
111 | // $"Error has been found",
112 | // OLEMSGICON.OLEMSGICON_WARNING,
113 | // OLEMSGBUTTON.OLEMSGBUTTON_OK,
114 | // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
115 | // );
116 | //}
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Helper/BaseViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Diagnostics;
4 | using System.Windows.Input;
5 |
6 | namespace AdjustNamespace.Helper
7 | {
8 | ///
9 | /// Класс, реализующий базовую функциональность viewmodel идеологии MVVM
10 | ///
11 | public class BaseViewModel : INotifyPropertyChanged, IDisposable
12 | {
13 |
14 | ///
15 | /// Событие изменения свойства
16 | ///
17 | public event PropertyChangedEventHandler? PropertyChanged;
18 |
19 | ///
20 | /// Тестовое свойство бросания исключения в случае не нахождения биндинга
21 | ///
22 | protected bool _throwOnInvalidPropertyName;
23 |
24 | ///
25 | /// конструктор
26 | ///
27 | /// Диспатчер WPF
28 | protected BaseViewModel()
29 | {
30 | }
31 |
32 | ///
33 | /// Активация евента изменения бинденого свойства
34 | ///
35 | protected void OnPropertyChanged()
36 | {
37 | OnPropertyChanged(string.Empty);
38 | }
39 |
40 | ///
41 | /// Активация евента изменения бинденого свойства
42 | ///
43 | ///
44 | protected virtual void OnPropertyChanged(string propertyName)
45 | {
46 | VerifyPropertyName(propertyName);
47 |
48 | var handler = PropertyChanged;
49 | if (handler != null)
50 | {
51 | var e = new PropertyChangedEventArgs(propertyName);
52 | handler(this, e);
53 | }
54 |
55 | CommandManager.InvalidateRequerySuggested();
56 | }
57 |
58 | [Conditional("DEBUG")]
59 | [DebuggerStepThrough]
60 | public void VerifyPropertyName(string propertyName)
61 | {
62 | if (!string.IsNullOrEmpty(propertyName))
63 | {
64 | // Verify that the property name matches a real,
65 | // public, instance property on this object.
66 | var propertiesList = TypeDescriptor.GetProperties(this);
67 | if (propertiesList[propertyName] == null)
68 | {
69 | var msg = "Invalid property name: " + propertyName;
70 |
71 | if (_throwOnInvalidPropertyName)
72 | {
73 | throw new Exception(msg);
74 | }
75 |
76 | Debug.Fail(msg);
77 | }
78 | }
79 | }
80 |
81 | protected virtual void DisposeViewModel()
82 | {
83 |
84 | }
85 |
86 | #region Implementation of IDisposable
87 |
88 | public void Dispose()
89 | {
90 | DisposeViewModel();
91 | }
92 |
93 | #endregion
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Helper/ChainViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace AdjustNamespace.Helper
2 | {
3 | public abstract class ChainViewModel : BaseViewModel
4 | {
5 | protected ChainViewModel()
6 | : base()
7 | {
8 | }
9 |
10 | public abstract System.Threading.Tasks.Task StartAsync();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Helper/DocumentChangerHelper.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Build.Framework.XamlTypes;
2 | using Microsoft.CodeAnalysis;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace AdjustNamespace.Helper
9 | {
10 | public static class DocumentChangerHelper
11 | {
12 | public static async Task ApplyModifiedDocumentAsync(
13 | this Workspace workspace,
14 | string filePath,
15 | Func provider
16 | )
17 | {
18 | if (workspace is null)
19 | {
20 | throw new ArgumentNullException(nameof(workspace));
21 | }
22 |
23 | if (filePath is null)
24 | {
25 | throw new ArgumentNullException(nameof(filePath));
26 | }
27 |
28 | if (provider is null)
29 | {
30 | throw new ArgumentNullException(nameof(provider));
31 | }
32 |
33 | bool r;
34 | do
35 | {
36 | var (document, syntaxRoot) = await workspace.GetDocumentAndSyntaxRootAsync(filePath);
37 | if (document == null || syntaxRoot == null)
38 | {
39 | //skip this document
40 | return;
41 | }
42 |
43 | var changedDocument = provider(document, syntaxRoot);
44 | if (changedDocument is null)
45 | {
46 | return;
47 | }
48 |
49 | r = workspace.TryApplyChanges(changedDocument.Project.Solution);
50 | }
51 | while (!r);
52 | }
53 |
54 | public static async Task ApplyModifiedDocumentAsync(
55 | this Workspace workspace,
56 | Func> provider
57 | )
58 | {
59 | if (workspace is null)
60 | {
61 | throw new ArgumentNullException(nameof(workspace));
62 | }
63 |
64 | if (provider is null)
65 | {
66 | throw new ArgumentNullException(nameof(provider));
67 | }
68 |
69 | bool r;
70 | do
71 | {
72 | var changedDocument = await provider(workspace);
73 | if (changedDocument is null)
74 | {
75 | return;
76 | }
77 |
78 | r = workspace.TryApplyChanges(changedDocument.Project.Solution);
79 | }
80 | while (!r);
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Helper/HashSetHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AdjustNamespace.Helper
6 | {
7 | internal static class HashSetHelper
8 | {
9 | public static void AddRange(this HashSet set, IEnumerable list)
10 | {
11 | foreach(var i in list)
12 | {
13 | set.Add(i);
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Helper/RoslynHelper.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 |
8 | namespace AdjustNamespace.Helper
9 | {
10 | public static class RoslynHelper
11 | {
12 | public static QualifiedNameSyntax? ToUpperSymbol(
13 | this QualifiedNameSyntax qns,
14 | SemanticModel semanticModel
15 | )
16 | {
17 | while (true)
18 | {
19 | var symbol = semanticModel.GetSymbolInfo(qns.Left).Symbol;
20 | if (symbol == null)
21 | {
22 | return null;
23 | }
24 | if (symbol.Kind != SymbolKind.NamedType)
25 | {
26 | return qns;
27 | }
28 |
29 | var pqns = qns.Left as QualifiedNameSyntax;
30 | if (pqns == null)
31 | {
32 | return null;
33 | }
34 |
35 | qns = pqns;
36 | }
37 |
38 | }
39 |
40 | public static bool IsGlobal(this SyntaxNode node)
41 | {
42 | if (node is null)
43 | {
44 | throw new System.ArgumentNullException(nameof(node));
45 | }
46 |
47 | return node.ToString().StartsWith("global::");
48 | }
49 |
50 | public static T? ToUpperSyntax(this SyntaxNode node)
51 | where T : SyntaxNode
52 | {
53 | while (node != null)
54 | {
55 | if (!(node.Parent is T))
56 | {
57 | return (T)node;
58 | }
59 |
60 | node = node.Parent;
61 | }
62 |
63 | return default;
64 | }
65 |
66 | public static SyntaxNode? GoDownTo(this SyntaxNode node, Type targetType)
67 | {
68 | if (node.GetType() == targetType)
69 | {
70 | return node;
71 | }
72 |
73 | var toProcess = node.ChildNodes().ToList();
74 |
75 | while (toProcess.Count > 0)
76 | {
77 | //check any children to match
78 | foreach (var child in toProcess)
79 | {
80 | if (child.GetType() == targetType)
81 | {
82 | return child;
83 | }
84 | }
85 |
86 | //not found in direct children
87 | //get children from next level of depth
88 | var toProcess2 = new List();
89 | foreach (var child in toProcess)
90 | {
91 | toProcess2.AddRange(child.ChildNodes());
92 | }
93 |
94 | toProcess = toProcess2;
95 | }
96 |
97 | return default;
98 | }
99 |
100 | public static List GetAllDescendants(
101 | this SyntaxNode s
102 | )
103 | where T : SyntaxNode
104 | {
105 | var r = s
106 | .DescendantNodes()
107 | .OfType()
108 | .ToList()
109 | ;
110 |
111 | return r;
112 | }
113 |
114 | public static IEnumerable GetAllTypes(this INamespaceSymbol @namespace)
115 | {
116 | foreach (var type in @namespace.GetTypeMembers())
117 | foreach (var nestedType in type.GetNestedTypes())
118 | yield return nestedType;
119 |
120 | foreach (var nestedNamespace in @namespace.GetNamespaceMembers())
121 | foreach (var type in nestedNamespace.GetAllTypes())
122 | yield return type;
123 | }
124 |
125 |
126 | public static IEnumerable GetNestedTypes(this INamedTypeSymbol type)
127 | {
128 | yield return type;
129 | foreach (var nestedType in type.GetTypeMembers()
130 | .SelectMany(nestedType => nestedType.GetNestedTypes()))
131 | yield return nestedType;
132 | }
133 |
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Helper/WpfHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Windows;
3 | using System.Windows.Media;
4 |
5 | namespace AdjustNamespace.Helper
6 | {
7 | public static class WpfHelper
8 | {
9 | public static IEnumerable FindLogicalChildren(this DependencyObject depObj) where T : DependencyObject
10 | {
11 | if (depObj != null)
12 | {
13 | foreach (var rawChild in LogicalTreeHelper.GetChildren(depObj))
14 | {
15 | if (rawChild is DependencyObject)
16 | {
17 | var child = (DependencyObject)rawChild;
18 | if (child is T)
19 | {
20 | yield return (T)child;
21 | }
22 |
23 | foreach (var childOfChild in child.FindLogicalChildren())
24 | {
25 | yield return childOfChild;
26 | }
27 | }
28 | }
29 | }
30 | }
31 | public static List FindVisualChildren(
32 | this DependencyObject obj
33 | )
34 | where TChildItem : DependencyObject
35 | {
36 | var result = new List();
37 |
38 | obj.FindVisualChildren(
39 | result
40 | );
41 |
42 | return result;
43 | }
44 |
45 | public static void FindVisualChildren(
46 | this DependencyObject obj,
47 | List result
48 | )
49 | where TChildItem : DependencyObject
50 | {
51 | for (var i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
52 | {
53 | var child = VisualTreeHelper.GetChild(obj, i);
54 |
55 | if (child is TChildItem tchi)
56 | {
57 | result.Add(tchi);
58 | }
59 | else
60 | {
61 | child.FindVisualChildren(result);
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/ImageMonikers.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging.Interop;
2 | using System;
3 |
4 | namespace AdjustNamespace
5 | {
6 | public static class ImageMonikers
7 | {
8 | public static ImageMoniker Logo
9 | {
10 | get;
11 | } = new ImageMoniker
12 | {
13 | Guid = new Guid("872022f4-493a-4d7b-97f5-8b474662c341"),
14 | Id = 0
15 | };
16 |
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Авдеев Вячеслав
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Logging.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Runtime.CompilerServices;
5 | using System.Threading;
6 |
7 | namespace AdjustNamespace
8 | {
9 | ///
10 | /// Logging helpers.
11 | /// Taken from https://github.com/bert2/microscope completely.
12 | /// Take a look to that repo, it's amazing!
13 | ///
14 | public static class Logging
15 | {
16 | private static readonly object @lock = new object();
17 |
18 | // Logs go to: C:\Users\\AppData\Local\Temp\dpdt_extension.*.log
19 | private static readonly string vsLogFile = $"{Path.GetTempPath()}/AdjustNamespace.vs.log";
20 |
21 | [Conditional("DEBUG")]
22 | public static void LogVS(
23 | object? data = null,
24 | [CallerFilePath] string? file = null,
25 | [CallerMemberName] string? method = null)
26 | => Log(vsLogFile, file!, method!, data);
27 |
28 | public static void Log(
29 | string logFile,
30 | string callingFile,
31 | string callingMethod,
32 | object? data = null)
33 | {
34 | lock (@lock)
35 | {
36 | File.AppendAllText(
37 | logFile,
38 | $"{DateTime.Now:HH:mm:ss.fff} "
39 | + $"{Process.GetCurrentProcess().Id,5} "
40 | + $"{Thread.CurrentThread.ManagedThreadId,3} "
41 | + $"{Path.GetFileNameWithoutExtension(callingFile)}.{callingMethod}()"
42 | + $"{(data == null ? "" : $": {data}")}\n");
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Namespace/NamespaceCenter.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using Microsoft.VisualStudio.LanguageServices;
4 | using Microsoft.VisualStudio.Threading;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Threading.Tasks;
8 | using System.Xml.Linq;
9 |
10 | namespace AdjustNamespace.Adjusting
11 | {
12 | ///
13 | /// Namespace state container. It accumulates a changes during adjusting.
14 | ///
15 | public class NamespaceCenter
16 | {
17 | private readonly Dictionary> _types;
18 |
19 | ///
20 | /// Emptyfied namespaces. They need to be removed at the end of adjusting procedure.
21 | ///
22 | private readonly HashSet _namespacesToRemove;
23 |
24 | private NamespaceCenter(
25 | Dictionary> types
26 | )
27 | {
28 | if (types is null)
29 | {
30 | throw new ArgumentNullException(nameof(types));
31 | }
32 |
33 | _types = types;
34 | _namespacesToRemove = new HashSet();
35 | }
36 |
37 | ///
38 | /// Filter incoming namespaces and return only those are allowed to delete
39 | /// (namespaces that does not exists after adjusting).
40 | ///
41 | public List GetRemovedNamespaces(
42 | IReadOnlyList namespacesToCheck
43 | )
44 | {
45 | if (namespacesToCheck is null)
46 | {
47 | throw new ArgumentNullException(nameof(namespacesToCheck));
48 | }
49 |
50 | if (namespacesToCheck.Count == 0)
51 | {
52 | return new List();
53 | }
54 |
55 | var toRemove = new List(namespacesToCheck.Count);
56 |
57 | foreach (var n in namespacesToCheck)
58 | {
59 | var nname = n.Name.ToString();
60 |
61 | if (!_namespacesToRemove.Contains(nname))
62 | {
63 | //there are a types in this namespace
64 | continue;
65 | }
66 |
67 | toRemove.Add(n);
68 | }
69 |
70 | return toRemove;
71 | }
72 |
73 | public void TypeRemoved(ITypeSymbol type)
74 | {
75 | var cnn = type.ContainingNamespace.ToDisplayString();
76 | if (!_types.TryGetValue(cnn, out var set))
77 | {
78 | return;
79 | }
80 |
81 | var tn = type.ToDisplayString();
82 |
83 | if (!set.Contains(tn))
84 | {
85 | return;
86 | }
87 |
88 | set.Remove(tn);
89 |
90 | if (set.Count == 0)
91 | {
92 | _namespacesToRemove.Add(cnn);
93 | }
94 | }
95 |
96 | ///
97 | /// Build a namespace center for a whole workspace.
98 | ///
99 | public static async Task CreateForAsync(
100 | VisualStudioWorkspace workspace
101 | )
102 | {
103 | if (workspace is null)
104 | {
105 | throw new ArgumentNullException(nameof(workspace));
106 | }
107 |
108 | var typeContainer = await TypeContainer.CreateForAsync(workspace);
109 |
110 | var types = new Dictionary>(typeContainer.DictByFullName.Count);
111 | foreach (var nte in typeContainer.DictByFullName.Values)
112 | {
113 | var key = nte.ContainingNamespaceName;
114 | if (!types.ContainsKey(key))
115 | {
116 | types[key] = new HashSet();
117 | }
118 | types[key].Add(nte.TypeFullName);
119 | }
120 |
121 | var result = new NamespaceCenter(types);
122 | return result;
123 | }
124 |
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Namespace/NamespaceTransition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AdjustNamespace.Namespace
6 | {
7 | public readonly struct NamespaceTransition
8 | {
9 | ///
10 | /// Original namespace name.
11 | ///
12 | public readonly string OriginalName;
13 |
14 | ///
15 | /// Desired (target) namespace name.
16 | /// (namespace name bringed in accordance with its file folders)
17 | ///
18 | public readonly string ModifiedName;
19 |
20 | ///
21 | /// Is this original namespace is root in the document.
22 | ///
23 | public readonly bool IsRoot;
24 |
25 | public NamespaceTransition(
26 | string originalName,
27 | string modifiedName,
28 | bool isRoot
29 | )
30 | {
31 | if (originalName is null)
32 | {
33 | throw new ArgumentNullException(nameof(originalName));
34 | }
35 |
36 | if (modifiedName is null)
37 | {
38 | throw new ArgumentNullException(nameof(modifiedName));
39 | }
40 |
41 | OriginalName = originalName;
42 | ModifiedName = modifiedName;
43 | IsRoot = isRoot;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Options/General.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using System.ComponentModel;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace AdjustNamespace.Options
6 | {
7 | internal partial class OptionsProvider
8 | {
9 | [ComVisible(true)]
10 | public class GeneralOptions : BaseOptionPage
11 | {
12 | }
13 | }
14 |
15 | public class General : BaseOptionModel
16 | {
17 | [Category("General")]
18 | [DisplayName("FilesAdjusted")]
19 | [Description("How many files were processed (adjusted namespaces).")]
20 | [DefaultValue(0)]
21 | [Browsable(false)]
22 | public int FilesAdjusted { get; set; } = 0;
23 |
24 | [Category("General")]
25 | [DisplayName("StarsGiven")]
26 | [Description("Stars are given already, no need to make a noise.")]
27 | [DefaultValue(false)]
28 | [Browsable(false)]
29 | public bool StarsGiven { get; set; } = false;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Predicate.cs:
--------------------------------------------------------------------------------
1 | using Document = Microsoft.CodeAnalysis.Document;
2 |
3 | namespace AdjustNamespace
4 | {
5 | public static class Predicate
6 | {
7 | public static bool IsProjectInScope(this Microsoft.CodeAnalysis.Project? project)
8 | {
9 | if (project == null)
10 | {
11 | return false;
12 | }
13 | if (!project.SupportsCompilation)
14 | {
15 | return false;
16 | }
17 | if (project.Language != "C#")
18 | {
19 | return false;
20 | }
21 | return true;
22 | }
23 |
24 | public static bool IsDocumentInScope(this Document? document)
25 | {
26 | if (document is null)
27 | {
28 | return false;
29 | }
30 | if (document.FilePath is null)
31 | {
32 | return false;
33 | }
34 | if (!document.SupportsSyntaxTree)
35 | {
36 | return false;
37 | }
38 | if (!document.SupportsSemanticModel)
39 | {
40 | return false;
41 | }
42 |
43 | return true;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Settings/AdjustNamespaceSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace AdjustNamespace.Settings
7 | {
8 | public class AdjustNamespaceSettings
9 | {
10 | public List SkippedFolderSuffixes
11 | {
12 | get;
13 | set;
14 | } = null!;
15 |
16 |
17 | public AdjustNamespaceSettings()
18 | {
19 | SkippedFolderSuffixes = new List();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Settings/AdjustNamespaceSettings2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace AdjustNamespace.Settings
7 | {
8 | public class AdjustNamespaceSettings2
9 | {
10 | private readonly string _solutionFolder;
11 |
12 | public readonly AdjustNamespaceSettings Settings;
13 |
14 | public AdjustNamespaceSettings2(
15 | string solutionFolder,
16 | AdjustNamespaceSettings settings
17 | )
18 | {
19 | if (solutionFolder is null)
20 | {
21 | throw new ArgumentNullException(nameof(solutionFolder));
22 | }
23 |
24 | if (settings is null)
25 | {
26 | throw new ArgumentNullException(nameof(settings));
27 | }
28 | _solutionFolder = solutionFolder;
29 | Settings = settings;
30 | }
31 |
32 | public bool IsSkippedFolder(string fullFolderPath)
33 | {
34 | fullFolderPath = Path.GetFullPath(fullFolderPath)
35 | .Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
36 |
37 | foreach (var sfs in Settings.SkippedFolderSuffixes)
38 | {
39 | if (Path.IsPathRooted(sfs))
40 | {
41 | var rsfs = Path.GetFullPath(sfs)
42 | .Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
43 |
44 | if (rsfs == fullFolderPath)
45 | {
46 | return true;
47 | }
48 | }
49 | else
50 | {
51 | var rsfs = Path.Combine(_solutionFolder, sfs)
52 | .Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
53 |
54 | if (rsfs == fullFolderPath)
55 | {
56 | return true;
57 | }
58 | }
59 | }
60 |
61 | return false;
62 | }
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Settings/SettingsReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 | using System.Xml.Serialization;
6 |
7 | namespace AdjustNamespace.Settings
8 | {
9 | public class SettingsReader
10 | {
11 | public const string SettingFileName = "adjust_namespaces_settings.xml";
12 |
13 | private static readonly XmlSerializer _serializer = new XmlSerializer(typeof(AdjustNamespaceSettings));
14 | private readonly string _solutionFolder;
15 |
16 | public SettingsReader(string solutionFolder)
17 | {
18 | if (solutionFolder is null)
19 | {
20 | throw new ArgumentNullException(nameof(solutionFolder));
21 | }
22 |
23 | _solutionFolder = solutionFolder;
24 | }
25 |
26 | public AdjustNamespaceSettings? ReadSettings(
27 | )
28 | {
29 | var settingsFilePath = Path.Combine(_solutionFolder, SettingFileName);
30 | if(!File.Exists(settingsFilePath))
31 | {
32 | return null;
33 | }
34 |
35 | using (var fs = new FileStream(settingsFilePath, FileMode.Open))
36 | {
37 | var result = (AdjustNamespaceSettings)_serializer.Deserialize(fs);
38 | return result;
39 | }
40 | }
41 |
42 | public void Save(
43 | AdjustNamespaceSettings settings
44 | )
45 | {
46 | if (settings is null)
47 | {
48 | throw new ArgumentNullException(nameof(settings));
49 | }
50 |
51 | var settingsFilePath = Path.Combine(_solutionFolder, SettingFileName);
52 | if (File.Exists(settingsFilePath))
53 | {
54 | File.Delete(settingsFilePath);
55 | }
56 |
57 | using (var fs = new FileStream(settingsFilePath, FileMode.Create))
58 | {
59 | _serializer.Serialize(
60 | fs,
61 | settings
62 | );
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/Control/PerformingUserControl.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
25 |
26 |
34 |
35 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/Control/PerformingUserControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace AdjustNamespace.UI.Control
4 | {
5 | ///
6 | /// Interaction logic for PerformingUserControl.xaml
7 | ///
8 | public partial class PerformingUserControl : UserControl
9 | {
10 | public PerformingUserControl()
11 | {
12 | InitializeComponent();
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/Control/PreparationUserControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace AdjustNamespace.UI.Control
4 | {
5 | ///
6 | /// Interaction logic for PreparationUserControl.xaml
7 | ///
8 | public partial class PreparationUserControl : UserControl
9 | {
10 | public PreparationUserControl()
11 | {
12 | InitializeComponent();
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/Control/SelectedUserControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace AdjustNamespace.UI.Control
4 | {
5 | ///
6 | /// Interaction logic for SelectedUserControl.xaml
7 | ///
8 | public partial class SelectedUserControl : UserControl
9 | {
10 | public SelectedUserControl()
11 | {
12 | InitializeComponent();
13 | }
14 |
15 | private void ListView_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
16 | {
17 | if (e.Key == System.Windows.Input.Key.Space)
18 | {
19 | e.Handled = true;
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/Control/SpaceKeyUpEventTrigger.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xaml.Behaviors;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows.Input;
8 |
9 | namespace AdjustNamespace.UI.Control
10 | {
11 | public class SpaceKeyDownEventTrigger : EventTrigger
12 | {
13 |
14 | public SpaceKeyDownEventTrigger()
15 | : base("KeyUp")
16 | {
17 | }
18 |
19 | protected override void OnEvent(EventArgs eventArgs)
20 | {
21 | var e = eventArgs as KeyEventArgs;
22 | if (e != null && e.Key == Key.Space)
23 | this.InvokeActions(eventArgs);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/FileEx.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace AdjustNamespace.UI.ViewModel
8 | {
9 | ///
10 | /// Extension for file from workspace.
11 | ///
12 | public readonly struct FileEx
13 | {
14 | public readonly string FolderPath;
15 | public readonly string FileName;
16 | public readonly string FilePath;
17 | public readonly string ProjectPath;
18 |
19 | public FileEx(
20 | string filePath,
21 | string projectPath
22 | )
23 | {
24 | if (filePath is null)
25 | {
26 | throw new ArgumentNullException(nameof(filePath));
27 | }
28 |
29 | if (projectPath is null)
30 | {
31 | throw new ArgumentNullException(nameof(projectPath));
32 | }
33 |
34 | var fi = new FileInfo(filePath);
35 | FolderPath = fi.Directory.FullName;
36 | FileName = fi.Name;
37 | FilePath = filePath;
38 | ProjectPath = projectPath;
39 | }
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/StepFactory/IStepFactory.cs:
--------------------------------------------------------------------------------
1 | namespace AdjustNamespace.UI.StepFactory
2 | {
3 | public interface IStepFactory
4 | {
5 | System.Threading.Tasks.Task CreateAsync(object argument);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/StepFactory/PerformingStepFactory.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.UI.Control;
2 | using System;
3 | using System.Windows.Controls;
4 | using AdjustNamespace.UI.ViewModel;
5 | using Microsoft.VisualStudio.PlatformUI;
6 |
7 | namespace AdjustNamespace.UI.StepFactory
8 | {
9 | public class PerformingStepFactory : IStepFactory
10 | {
11 | private readonly VsServices _vss;
12 | private readonly DialogWindow _window;
13 | private readonly ContentControl _targetControl;
14 |
15 | public PerformingStepFactory(
16 | VsServices vss,
17 | DialogWindow window,
18 | ContentControl targetControl
19 | )
20 | {
21 | if (window is null)
22 | {
23 | throw new ArgumentNullException(nameof(window));
24 | }
25 |
26 | if (targetControl is null)
27 | {
28 | throw new ArgumentNullException(nameof(targetControl));
29 | }
30 |
31 | _vss = vss;
32 | _window = window;
33 | _targetControl = targetControl;
34 | }
35 |
36 | public async System.Threading.Tasks.Task CreateAsync(object argument)
37 | {
38 | var v = new PerformingUserControl();
39 |
40 | var vm = new PerformingViewModel(
41 | _vss,
42 | () => _window.Close(),
43 | (PerformingParameters)argument
44 | );
45 |
46 | v.DataContext = vm;
47 | _targetControl.Content = v;
48 |
49 | try
50 | {
51 | await vm!.StartAsync();
52 | }
53 | catch (Exception excp)
54 | {
55 | _targetControl.Content = excp.Message + Environment.NewLine + excp.StackTrace;
56 | _targetControl.Foreground = System.Windows.Media.Brushes.Red;
57 | Logging.LogVS(excp);
58 | }
59 | }
60 |
61 | }
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/StepFactory/PreparationStepFactory.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.UI.Control;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Windows.Controls;
5 | using AdjustNamespace.UI.ViewModel;
6 |
7 | namespace AdjustNamespace.UI.StepFactory
8 | {
9 | public class PreparationStepFactory : IStepFactory
10 | {
11 | private readonly VsServices _vss;
12 | private readonly ContentControl _targetControl;
13 | private readonly IStepFactory _nextStepFactory;
14 |
15 | public PreparationStepFactory(
16 | VsServices vss,
17 | ContentControl targetControl,
18 | IStepFactory nextStepFactory
19 | )
20 | {
21 | if (targetControl is null)
22 | {
23 | throw new ArgumentNullException(nameof(targetControl));
24 | }
25 |
26 | if (nextStepFactory is null)
27 | {
28 | throw new ArgumentNullException(nameof(nextStepFactory));
29 | }
30 |
31 | _vss = vss;
32 | _targetControl = targetControl;
33 | _nextStepFactory = nextStepFactory;
34 | }
35 |
36 | public async System.Threading.Tasks.Task CreateAsync(object argument)
37 | {
38 | var v = new PreparationUserControl();
39 |
40 | var vm = new PreparationStepViewModel(
41 | _vss,
42 | _nextStepFactory,
43 | (HashSet)argument
44 | );
45 |
46 | v.DataContext = vm;
47 | _targetControl.Content = v;
48 |
49 | await vm!.StartAsync();
50 | }
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/StepFactory/SelectedStepFactory.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.UI.Control;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Windows.Controls;
5 | using AdjustNamespace.UI.ViewModel;
6 |
7 | namespace AdjustNamespace.UI.StepFactory
8 | {
9 | public class SelectedStepFactory : IStepFactory
10 | {
11 | private readonly VsServices _vss;
12 | private readonly ContentControl _targetControl;
13 | private readonly IStepFactory _nextStepFactory;
14 |
15 | public SelectedStepFactory(
16 | VsServices vss,
17 | ContentControl targetControl,
18 | IStepFactory nextStepFactory
19 | )
20 | {
21 | if (targetControl is null)
22 | {
23 | throw new ArgumentNullException(nameof(targetControl));
24 | }
25 |
26 | if (nextStepFactory is null)
27 | {
28 | throw new ArgumentNullException(nameof(nextStepFactory));
29 | }
30 |
31 | _vss = vss;
32 | _targetControl = targetControl;
33 | _nextStepFactory = nextStepFactory;
34 | }
35 |
36 | public async System.Threading.Tasks.Task CreateAsync(object argument)
37 | {
38 | var a = (SelectedStepParameters)argument;
39 |
40 | var v = new SelectedUserControl();
41 |
42 | var vm = new SelectedStepViewModel(
43 | _vss,
44 | _nextStepFactory,
45 | a
46 | );
47 |
48 | v.DataContext = vm;
49 | _targetControl.Content = v;
50 |
51 | try
52 | {
53 | await vm!.StartAsync();
54 | }
55 | catch (Exception excp)
56 | {
57 | _targetControl.Content = excp.Message + Environment.NewLine + excp.StackTrace;
58 | _targetControl.Foreground = System.Windows.Media.Brushes.Red;
59 | Logging.LogVS(excp);
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/ViewModel/PerformingParameters.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace AdjustNamespace.UI.ViewModel
4 | {
5 | public readonly struct PerformingParameters
6 | {
7 | public readonly List SubjectFilePaths;
8 | public readonly NamespaceReplaceRegex ReplaceRegex;
9 | public readonly bool OpenFilesToEnableUndo;
10 |
11 | public PerformingParameters(
12 | List subjectFilePaths,
13 | NamespaceReplaceRegex replaceRegex,
14 | bool openFilesToEnableUndo
15 | )
16 | {
17 | if (subjectFilePaths is null)
18 | {
19 | throw new ArgumentNullException(nameof(subjectFilePaths));
20 | }
21 |
22 | SubjectFilePaths = subjectFilePaths;
23 | ReplaceRegex = replaceRegex;
24 | OpenFilesToEnableUndo = openFilesToEnableUndo;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/ViewModel/Select/ISelectItemViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AdjustNamespace.UI.ViewModel.Select
6 | {
7 | public interface ISelectItemViewModel
8 | {
9 | FileEx? FileEx
10 | {
11 | get;
12 | }
13 |
14 | bool? IsChecked
15 | {
16 | get;
17 | set;
18 | }
19 |
20 | bool IsSelected
21 | {
22 | get;
23 | set;
24 | }
25 |
26 | string ItemPath
27 | {
28 | get;
29 | }
30 |
31 | ///
32 | /// Clear the references to the parent.
33 | ///
34 | void Clear();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/ViewModel/Select/SelectFileViewModel.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using System.Windows;
6 |
7 | namespace AdjustNamespace.UI.ViewModel.Select
8 | {
9 | public class SelectFileViewModel : BaseViewModel, ISelectItemViewModel
10 | {
11 | private SelectFolderViewModel? _parentViewModel;
12 |
13 | private bool _isChecked; //file cannot be in the middle state
14 | private bool _isSelected;
15 |
16 | public FileEx? FileEx
17 | {
18 | get;
19 | }
20 |
21 | public FontWeight FontWeight => FontWeights.Regular;
22 |
23 | public Thickness LeftMargin
24 | {
25 | get;
26 | }
27 |
28 | public bool? IsChecked
29 | {
30 | get => _isChecked;
31 | set
32 | {
33 | _isChecked = value.GetValueOrDefault(false);
34 | OnPropertyChanged(nameof(IsChecked));
35 | _parentViewModel?.RefreshStatus();
36 | }
37 | }
38 |
39 | public bool IsSelected
40 | {
41 | get => _isSelected;
42 | set => _isSelected = value;
43 | }
44 |
45 | public string ItemPath
46 | {
47 | get;
48 | }
49 |
50 | public void SetCheckedStatusFromParent(bool isChecked)
51 | {
52 | _isChecked = isChecked;
53 | OnPropertyChanged(nameof(IsChecked));
54 | }
55 |
56 |
57 | public SelectFileViewModel(
58 | FileEx fileEx,
59 | SelectFolderViewModel parentViewModel
60 | )
61 | {
62 | if (parentViewModel is null)
63 | {
64 | throw new ArgumentNullException(nameof(parentViewModel));
65 | }
66 |
67 | FileEx = fileEx;
68 |
69 | var level = 2;
70 | LeftMargin = new Thickness(level * 5, 0, 0, 0);
71 | ItemPath = fileEx.FileName;
72 | _parentViewModel = parentViewModel;
73 | IsChecked = true;
74 | }
75 |
76 | public void Clear()
77 | {
78 | _parentViewModel = null;
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/ViewModel/Select/SelectFolderViewModel.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Windows;
7 |
8 | namespace AdjustNamespace.UI.ViewModel.Select
9 | {
10 | public class SelectFolderViewModel : BaseViewModel, ISelectItemViewModel
11 | {
12 | private List _files;
13 |
14 | private bool _isSelected;
15 | private SelectedStepViewModel? _parent;
16 |
17 | public IReadOnlyList Files => _files;
18 |
19 | public FileEx? FileEx => null;
20 |
21 | public Thickness LeftMargin
22 | {
23 | get;
24 | }
25 |
26 | public FontWeight FontWeight => FontWeights.Bold;
27 |
28 | public bool? IsChecked
29 | {
30 | get
31 | {
32 | var q = _files.Select(f => f.IsChecked).Distinct().ToList();
33 | if (q.Count == 1)
34 | {
35 | return q[0];
36 | }
37 |
38 | return null;
39 | }
40 |
41 | set
42 | {
43 | foreach (var file in _files)
44 | {
45 | file.SetCheckedStatusFromParent(value.GetValueOrDefault(false));
46 | }
47 |
48 | _parent?.RefreshStatus();
49 | OnPropertyChanged(nameof(IsChecked));
50 | }
51 | }
52 |
53 | public bool IsSelected
54 | {
55 | get => _isSelected;
56 | set => _isSelected = value;
57 | }
58 |
59 | public string ItemPath
60 | {
61 | get;
62 | }
63 |
64 |
65 | public SelectFolderViewModel(
66 | SelectedStepViewModel parent,
67 | string folderPath
68 | )
69 | {
70 | if (parent is null)
71 | {
72 | throw new ArgumentNullException(nameof(parent));
73 | }
74 |
75 | if (folderPath is null)
76 | {
77 | throw new ArgumentNullException(nameof(folderPath));
78 | }
79 |
80 | _files = new List();
81 |
82 | var level = 0;
83 | LeftMargin = new Thickness(level * 5, 0, 0, 0);
84 | _parent = parent;
85 | ItemPath = folderPath;
86 | IsChecked = true;
87 | }
88 |
89 | public void AddFiles(
90 | List files
91 | )
92 | {
93 | if (files is null)
94 | {
95 | throw new ArgumentNullException(nameof(files));
96 | }
97 |
98 | _files.AddRange(files);
99 | }
100 |
101 | public void RefreshStatus()
102 | {
103 | _parent?.RefreshStatus();
104 | OnPropertyChanged();
105 | }
106 |
107 | public void Clear()
108 | {
109 | _parent = null;
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/UI/ViewModel/SelectedStepParameters.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.UI.ViewModel;
2 | using AdjustNamespace;
3 | using System.Collections.Generic;
4 |
5 | namespace AdjustNamespace.UI.ViewModel
6 | {
7 | public readonly struct SelectedStepParameters
8 | {
9 | public readonly List FileExs;
10 | public readonly NamespaceReplaceRegex ReplaceRegex;
11 |
12 | public SelectedStepParameters(List fileExs, NamespaceReplaceRegex replaceRegex)
13 | {
14 | FileExs = fileExs;
15 | ReplaceRegex = replaceRegex;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/VsServices.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Settings;
2 | using EnvDTE;
3 | using EnvDTE80;
4 | using Microsoft.VisualStudio.ComponentModelHost;
5 | using Microsoft.VisualStudio.LanguageServices;
6 | using System.IO;
7 | using System.Text.RegularExpressions;
8 | using System.Threading.Tasks;
9 |
10 | namespace AdjustNamespace
11 | {
12 | public sealed class NamespaceReplaceRegex
13 | {
14 | public string ReplaceRegex
15 | {
16 | get;
17 | }
18 |
19 | public string ReplacedString
20 | {
21 | get;
22 | }
23 |
24 | public NamespaceReplaceRegex(string replaceRegex, string replacedString)
25 | {
26 | ReplaceRegex = replaceRegex;
27 | ReplacedString = replacedString;
28 | }
29 |
30 | public string Modify(string myNamespace)
31 | {
32 | if(string.IsNullOrEmpty(ReplaceRegex))
33 | {
34 | return myNamespace;
35 | }
36 | if (string.IsNullOrEmpty(ReplacedString))
37 | {
38 | return myNamespace;
39 | }
40 |
41 | var result = Regex.Replace(myNamespace, ReplaceRegex, ReplacedString);
42 | return result;
43 | }
44 | }
45 |
46 | public readonly struct VsServices
47 | {
48 | public readonly IAsyncServiceProvider ServiceProvider;
49 | public readonly DTE2 Dte;
50 | public readonly IComponentModel ComponentModel;
51 | public readonly VisualStudioWorkspace Workspace;
52 | public readonly SettingsReader SettingsReader;
53 | public readonly AdjustNamespaceSettings2 Settings;
54 |
55 | private VsServices(
56 | Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider,
57 | DTE2 dte,
58 | IComponentModel componentModel,
59 | VisualStudioWorkspace workspace
60 | )
61 | {
62 | if (serviceProvider is null)
63 | {
64 | throw new ArgumentNullException(nameof(serviceProvider));
65 | }
66 |
67 | if (dte is null)
68 | {
69 | throw new ArgumentNullException(nameof(dte));
70 | }
71 |
72 | if (componentModel is null)
73 | {
74 | throw new ArgumentNullException(nameof(componentModel));
75 | }
76 |
77 | if (workspace is null)
78 | {
79 | throw new ArgumentNullException(nameof(workspace));
80 | }
81 |
82 | ServiceProvider = serviceProvider;
83 | Dte = dte;
84 | ComponentModel = componentModel;
85 | Workspace = workspace;
86 |
87 | var solutionFolder = new FileInfo(workspace.CurrentSolution.FilePath).Directory.FullName;
88 |
89 | SettingsReader = new SettingsReader(solutionFolder);
90 | Settings = new AdjustNamespaceSettings2(
91 | solutionFolder,
92 | SettingsReader.ReadSettings() ?? new AdjustNamespaceSettings()
93 | );
94 | }
95 |
96 | public async Task OpenFileAsync(
97 | string documentFullPath
98 | )
99 | {
100 | _ = await VS.Documents.OpenAsync(documentFullPath);
101 | }
102 |
103 | public static async Task CreateAsync(
104 | Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider
105 | )
106 | {
107 | if (serviceProvider is null)
108 | {
109 | throw new ArgumentNullException(nameof(serviceProvider));
110 | }
111 |
112 | var dte = await serviceProvider.GetServiceAsync(typeof(DTE)) as DTE2;
113 | if (dte == null)
114 | {
115 | throw new InvalidOperationException("Can't create a dte");
116 | }
117 |
118 | var componentModel = (IComponentModel)(await serviceProvider.GetServiceAsync(typeof(SComponentModel)))!;
119 | if (componentModel == null)
120 | {
121 | throw new InvalidOperationException("Can't create a component model");
122 | }
123 |
124 | var workspace = componentModel.GetService();
125 | if (workspace == null)
126 | {
127 | throw new InvalidOperationException("Can't create a workspace");
128 | }
129 |
130 | return new VsServices(serviceProvider, dte, componentModel, workspace);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Window/AdjustNamespaceWindow.xaml:
--------------------------------------------------------------------------------
1 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Window/AdjustNamespaceWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Options;
2 | using AdjustNamespace.UI.StepFactory;
3 | using Microsoft.VisualStudio.PlatformUI;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text.RegularExpressions;
7 | using System.Windows;
8 |
9 | namespace AdjustNamespace.Window
10 | {
11 | ///
12 | /// Interaction logic for AdjustNamespaceWindow.xaml
13 | ///
14 | public partial class AdjustNamespaceWindow : DialogWindow
15 | {
16 | private readonly Func _factory;
17 |
18 | public AdjustNamespaceWindow(
19 | Func factory
20 | )
21 | {
22 | if (factory is null)
23 | {
24 | throw new ArgumentNullException(nameof(factory));
25 | }
26 |
27 | _factory = factory;
28 |
29 | InitializeComponent();
30 | }
31 |
32 |
33 | private async void DialogWindow_Loaded(object sender, RoutedEventArgs e)
34 | {
35 | try
36 | {
37 | var showAwardCheckBox = false;
38 | if (!General.Instance.StarsGiven)
39 | {
40 | if (General.Instance.FilesAdjusted >= 20)
41 | {
42 | showAwardCheckBox = true;
43 | }
44 | }
45 |
46 | this.AwardCheckBox.Visibility = showAwardCheckBox ? Visibility.Visible : Visibility.Collapsed;
47 |
48 | await _factory(this);
49 | }
50 | catch (Exception ex)
51 | {
52 | Logging.LogVS(ex);
53 | }
54 | }
55 |
56 | private void DialogWindow_Closed(object sender, EventArgs e)
57 | {
58 | if(this.AwardCheckBox.IsChecked.GetValueOrDefault(false))
59 | {
60 | General.Instance.StarsGiven = true;
61 |
62 | System.Diagnostics.Process.Start("https://marketplace.visualstudio.com/items?itemName=lsoft.AdjustNamespaceVisualStudioExtension2022&ssr=false#review-details");
63 | }
64 | }
65 | public static AdjustNamespaceWindow Create(
66 | VsServices vss,
67 | HashSet filePaths
68 | )
69 | {
70 | var window = new AdjustNamespaceWindow(
71 | async anw =>
72 | {
73 | var perfsf = new PerformingStepFactory(
74 | vss,
75 | anw,
76 | anw.CenterContentControl
77 | );
78 |
79 | var selsf = new SelectedStepFactory(
80 | vss,
81 | anw.CenterContentControl,
82 | perfsf
83 | );
84 |
85 | var prepsf = new PreparationStepFactory(
86 | vss,
87 | anw.CenterContentControl,
88 | selsf
89 | );
90 |
91 | await prepsf.CreateAsync(filePaths);
92 | }
93 | );
94 |
95 | return window;
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Window/EditSkippedPathsWindow.xaml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
43 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
69 |
76 |
83 |
90 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/BodyProvider/ClosedXamlBodyProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace AdjustNamespace.Xaml.BodyProvider
7 | {
8 | public sealed class ClosedXamlBodyProvider : IXamlBodyProvider
9 | {
10 | public string XamlFilePath
11 | {
12 | get;
13 | }
14 |
15 | public ClosedXamlBodyProvider(
16 | string xamlFilePath
17 | )
18 | {
19 | if (xamlFilePath is null)
20 | {
21 | throw new ArgumentNullException(nameof(xamlFilePath));
22 | }
23 |
24 | XamlFilePath = xamlFilePath;
25 | }
26 |
27 | public string ReadText()
28 | {
29 | var result = File.ReadAllText(XamlFilePath);
30 |
31 | return result;
32 | }
33 |
34 | public void UpdateText(string text)
35 | {
36 | File.WriteAllText(XamlFilePath, text);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/BodyProvider/IXamlBodyProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AdjustNamespace.Xaml.BodyProvider
6 | {
7 | public interface IXamlBodyProvider
8 | {
9 | string XamlFilePath
10 | {
11 | get;
12 | }
13 |
14 | string ReadText();
15 |
16 |
17 | void UpdateText(string text);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/BodyProvider/OpenedXamlBodyProvider.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using Community.VisualStudio.Toolkit;
3 | using EnvDTE;
4 | using Microsoft.VisualStudio.Threading;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Text;
9 | using System.Threading;
10 |
11 | namespace AdjustNamespace.Xaml.BodyProvider
12 | {
13 | public sealed class OpenedXamlBodyProvider : IXamlBodyProvider
14 | {
15 | private readonly VsServices _vss;
16 | private DocumentView? _dw;
17 |
18 | public string XamlFilePath
19 | {
20 | get;
21 | }
22 |
23 |
24 | public OpenedXamlBodyProvider(
25 | VsServices vss,
26 | string xamlFilePath
27 | )
28 | {
29 | if (xamlFilePath is null)
30 | {
31 | throw new ArgumentNullException(nameof(xamlFilePath));
32 | }
33 | _vss = vss;
34 | XamlFilePath = xamlFilePath;
35 | }
36 |
37 | public async Task OpenAsync()
38 | {
39 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
40 |
41 | //var (r, subjectProject, subjectProjectItem) = await SolutionHelper.TryGetProjectItemAsync(XamlFilePath);
42 |
43 | //if (!r)
44 | //{
45 | // throw new InvalidOperationException($"File {XamlFilePath} not found!");
46 | //}
47 |
48 | _dw = await VS.Documents.OpenViaProjectAsync(XamlFilePath);
49 | }
50 |
51 | public string ReadText()
52 | {
53 | Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
54 |
55 | if (_dw == null)
56 | {
57 | throw new InvalidOperationException("Please open document before retrieving its text");
58 | }
59 |
60 | var result = _dw!.TextView!.TextSnapshot.GetText();
61 | return result;
62 | }
63 |
64 | public void UpdateText(string text)
65 | {
66 | Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
67 |
68 | if (_dw == null)
69 | {
70 | throw new InvalidOperationException("Please open document before saving its text");
71 | }
72 |
73 | var edit = _dw!.TextView!.TextBuffer.CreateEdit();
74 | edit.Delete(0, edit.Snapshot.GetText().Length);
75 | edit.Insert(0, text);
76 | edit.Apply();
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/IXamlPerformable.cs:
--------------------------------------------------------------------------------
1 | namespace AdjustNamespace.Xaml.Positioned
2 | {
3 | public interface IXamlPerformable : IXamlPositioned
4 | {
5 | bool Perform(
6 | XamlStructure structure,
7 | string sourceNamespace,
8 | string objectClassName,
9 | string targetNamespace,
10 | ref string xaml,
11 | out XamlXmlns? newXmlns
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/IXamlPositioned.cs:
--------------------------------------------------------------------------------
1 | namespace AdjustNamespace.Xaml.Positioned
2 | {
3 | public interface IXamlPositioned
4 | {
5 | int Index
6 | {
7 | get;
8 | }
9 |
10 | int Length
11 | {
12 | get;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/XamlAttributeReference.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AdjustNamespace.Xaml.Positioned
4 | {
5 | public class XamlAttributeReference : IXamlPerformable
6 | {
7 | public int Index
8 | {
9 | get;
10 | }
11 | public int Length
12 | {
13 | get;
14 | }
15 | public string Prefix
16 | {
17 | get;
18 | }
19 | public string Alias
20 | {
21 | get;
22 | }
23 | public string ClassName
24 | {
25 | get;
26 | }
27 |
28 | public XamlAttributeReference(
29 | int index,
30 | int length,
31 | string prefix,
32 | string alias,
33 | string className
34 | )
35 | {
36 | Index = index;
37 | Length = length;
38 | Alias = alias;
39 | ClassName = className;
40 | Prefix = prefix;
41 | }
42 |
43 | public bool Perform(
44 | XamlStructure structure,
45 | string sourceNamespace,
46 | string objectClassName,
47 | string targetNamespace,
48 | ref string xaml,
49 | out XamlXmlns? newXmlns
50 | )
51 | {
52 | if (sourceNamespace == null)
53 | throw new ArgumentNullException(nameof(sourceNamespace));
54 |
55 | if (objectClassName == null)
56 | throw new ArgumentNullException(nameof(objectClassName));
57 |
58 | if (targetNamespace == null)
59 | throw new ArgumentNullException(nameof(targetNamespace));
60 |
61 | if (xaml == null)
62 | throw new ArgumentNullException(nameof(xaml));
63 |
64 | newXmlns = null;
65 |
66 | if (ClassName != objectClassName)
67 | {
68 | return false;
69 | }
70 |
71 | var sourceXmlns = structure.GetByAlias(Alias);
72 | if (sourceXmlns.Namespace != sourceNamespace)
73 | {
74 | return false;
75 | }
76 |
77 | //match!
78 |
79 | //get or create new xmlns
80 | var targetXmlns = structure.TryGetByNamespace(targetNamespace);
81 | if (targetXmlns == null)
82 | {
83 | targetXmlns = new XamlXmlns(
84 | sourceXmlns,
85 | targetNamespace
86 | );
87 | newXmlns = targetXmlns;
88 | }
89 |
90 | var xPrefix = structure.GetXPrefix();
91 |
92 | xaml = xaml.Substring(0, Index)
93 | + $"{{{xPrefix.Alias}:{Prefix} {targetXmlns.Alias}:{ClassName}"
94 | + xaml.Substring(Index + Length)
95 | ;
96 | return true;
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/XamlClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AdjustNamespace.Xaml.Positioned
4 | {
5 | public class XamlClass : IXamlPerformable
6 | {
7 | public int Index
8 | {
9 | get;
10 | }
11 | public int Length
12 | {
13 | get;
14 | }
15 | public string Namespace
16 | {
17 | get;
18 | }
19 | public string ClassName
20 | {
21 | get;
22 | }
23 |
24 | public XamlClass(
25 | int index,
26 | int length,
27 | string fullClassName
28 | )
29 | {
30 | Index = index;
31 | Length = length;
32 |
33 | var dotIndex = fullClassName.LastIndexOf('.');
34 | if (dotIndex > 0)
35 | {
36 | Namespace = fullClassName.Substring(0, dotIndex);
37 | ClassName = fullClassName.Substring(dotIndex + 1);
38 | }
39 | else
40 | {
41 | Namespace = string.Empty;
42 | ClassName = fullClassName;
43 | }
44 | }
45 |
46 | public bool Perform(
47 | XamlStructure structure,
48 | string sourceNamespace,
49 | string objectClassName,
50 | string targetNamespace,
51 | ref string xaml,
52 | out XamlXmlns? newXmlns
53 | )
54 | {
55 | newXmlns = null;
56 |
57 | if (ClassName != objectClassName)
58 | {
59 | return false;
60 | }
61 |
62 | if (Namespace != sourceNamespace)
63 | {
64 | return false;
65 | }
66 |
67 | //match!
68 |
69 | var xPrefix = structure.GetXPrefix();
70 |
71 | xaml = xaml.Substring(0, Index)
72 | + $@"{xPrefix.Alias}:Class=""{targetNamespace}.{ClassName}"""
73 | + xaml.Substring(Index + Length)
74 | ;
75 | return true;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/XamlControl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AdjustNamespace.Xaml.Positioned
4 | {
5 | public class XamlControl : IXamlPerformable
6 | {
7 | public int Index
8 | {
9 | get;
10 | }
11 | public int Length
12 | {
13 | get;
14 | }
15 | public string TagPrefix
16 | {
17 | get;
18 | }
19 | public string Alias
20 | {
21 | get;
22 | }
23 | public string ClassName
24 | {
25 | get;
26 | }
27 |
28 | public XamlControl(
29 | int index,
30 | int length,
31 | string tagPrefix,
32 | string alias,
33 | string className
34 | )
35 | {
36 | Index = index;
37 | Length = length;
38 | TagPrefix = tagPrefix;
39 | Alias = alias;
40 | ClassName = className;
41 | }
42 |
43 | public bool Perform(
44 | XamlStructure structure,
45 | string sourceNamespace,
46 | string objectClassName,
47 | string targetNamespace,
48 | ref string xaml,
49 | out XamlXmlns? newXmlns
50 | )
51 | {
52 | if (sourceNamespace == null)
53 | throw new ArgumentNullException(nameof(sourceNamespace));
54 |
55 | if (objectClassName == null)
56 | throw new ArgumentNullException(nameof(objectClassName));
57 |
58 | if (targetNamespace == null)
59 | throw new ArgumentNullException(nameof(targetNamespace));
60 |
61 | if (xaml == null)
62 | throw new ArgumentNullException(nameof(xaml));
63 |
64 | newXmlns = null;
65 |
66 | if (ClassName != objectClassName)
67 | {
68 | return false;
69 | }
70 |
71 | var sourceXmlns = structure.GetByAlias(Alias);
72 | if (sourceXmlns.Namespace != sourceNamespace)
73 | {
74 | return false;
75 | }
76 |
77 | //match!
78 |
79 | //get or create new xmlns
80 | var targetXmlns = structure.TryGetByNamespace(targetNamespace);
81 | if (targetXmlns == null)
82 | {
83 | targetXmlns = new XamlXmlns(
84 | sourceXmlns,
85 | targetNamespace
86 | );
87 | newXmlns = targetXmlns;
88 | }
89 |
90 | xaml = xaml.Substring(0, Index)
91 | + $"<{TagPrefix}{targetXmlns.Alias}:{ClassName}"
92 | + xaml.Substring(Index + Length)
93 | ;
94 | return true;
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/XamlX.cs:
--------------------------------------------------------------------------------
1 | namespace AdjustNamespace.Xaml.Positioned
2 | {
3 | public class XamlX : IXamlPositioned
4 | {
5 | public int Index
6 | {
7 | get;
8 | }
9 | public int Length
10 | {
11 | get;
12 | }
13 | public string Alias
14 | {
15 | get;
16 | }
17 |
18 | public XamlX(int index, int length, string alias)
19 | {
20 | Index = index;
21 | Length = length;
22 | Alias = alias;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/Positioned/XamlXmlns.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | namespace AdjustNamespace.Xaml.Positioned
5 | {
6 | public class XamlXmlns : IXamlPositioned
7 | {
8 | public int Index
9 | {
10 | get;
11 | }
12 | public int Length
13 | {
14 | get;
15 | }
16 | public string Alias
17 | {
18 | get;
19 | }
20 | public string Namespace
21 | {
22 | get;
23 | }
24 | public bool Saved
25 | {
26 | get;
27 | }
28 | public string Suffix
29 | {
30 | get;
31 | }
32 |
33 | public XamlXmlns(int index, int length, string alias, string @namespace, string suffix)
34 | {
35 | Index = index;
36 | Length = length;
37 | Alias = alias;
38 | Namespace = @namespace;
39 | Saved = true;
40 | Suffix = suffix;
41 | }
42 |
43 | public XamlXmlns(
44 | XamlXmlns xmlns,
45 | string targetNamespace
46 | )
47 | {
48 | Index = xmlns.Index + Length;
49 | Length = 0;
50 | Alias = GetLastWord(targetNamespace) + GetPartOfGuid();
51 | Namespace = targetNamespace;
52 | Saved = false;
53 | Suffix = xmlns.Suffix;
54 | }
55 |
56 | internal void SaveTo(ref string xaml, ref int indexToInsert)
57 | {
58 | var s = $@" xmlns:{Alias}=""clr-namespace:{Namespace}{Suffix}""";
59 | xaml = xaml.Insert(indexToInsert, s);
60 | indexToInsert += s.Length;
61 | }
62 |
63 | internal void Remove(ref string xaml)
64 | {
65 | xaml = xaml.Substring(0, Index) + xaml.Substring(Index + Length);
66 | }
67 |
68 | private string GetLastWord(string s)
69 | {
70 | if (s.Contains('.'))
71 | {
72 | return s.Substring(s.LastIndexOf('.') + 1);
73 | }
74 |
75 | return s;
76 | }
77 |
78 | private string GetPartOfGuid()
79 | {
80 | var g = Guid.NewGuid().ToString();
81 | g = g.Substring(0, g.IndexOf('-'));
82 |
83 | return g;
84 | }
85 |
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/XamlEngine.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Helper;
2 | using AdjustNamespace.Xaml.BodyProvider;
3 | using EnvDTE;
4 | using Microsoft.VisualStudio.Shell;
5 | using Microsoft.VisualStudio.Shell.Interop;
6 | using Microsoft.VisualStudio.TextManager.Interop;
7 | using System;
8 |
9 | namespace AdjustNamespace.Xaml
10 | {
11 | public class XamlEngine
12 | {
13 | private readonly VsServices _vss;
14 |
15 | public XamlEngine(
16 | VsServices vss
17 | )
18 | {
19 | _vss = vss;
20 | }
21 |
22 | public async System.Threading.Tasks.Task CreateDocumentAsync(
23 | bool openFilesToEnableUndo,
24 | string xamlFilePath
25 | )
26 | {
27 | var bodyProvider = await CreateBodyProviderAsync(openFilesToEnableUndo, xamlFilePath);
28 |
29 | return new XamlDocument(bodyProvider);
30 | }
31 |
32 | private async System.Threading.Tasks.Task CreateBodyProviderAsync(
33 | bool openFilesToEnableUndo,
34 | string xamlFilePath
35 | )
36 | {
37 | IXamlBodyProvider bodyProvider;
38 | if (openFilesToEnableUndo)
39 | {
40 | var obp = new OpenedXamlBodyProvider(_vss, xamlFilePath);
41 | await obp.OpenAsync();
42 |
43 | bodyProvider = obp;
44 | }
45 | else
46 | {
47 | bodyProvider = new ClosedXamlBodyProvider(xamlFilePath);
48 | }
49 |
50 | return bodyProvider;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/AdjustNamespace.VsixShared/Xaml/XamlStructure.cs:
--------------------------------------------------------------------------------
1 | using AdjustNamespace.Xaml.Positioned;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace AdjustNamespace.Xaml
8 | {
9 | ///
10 | /// Interesting structures from Xaml document.
11 | ///
12 | public readonly struct XamlStructure
13 | {
14 | public readonly XamlX XPrefix;
15 | public readonly List Xmlns;
16 | public readonly List Controls;
17 | public readonly List RefFroms;
18 | public readonly List Classes;
19 |
20 | public XamlStructure(
21 | XamlX xPrefix,
22 | List xmlns,
23 | List controls,
24 | List refFroms,
25 | List classes
26 | )
27 | {
28 | if (xPrefix is null)
29 | {
30 | throw new ArgumentNullException(nameof(xPrefix));
31 | }
32 |
33 | if (xmlns is null)
34 | {
35 | throw new ArgumentNullException(nameof(xmlns));
36 | }
37 |
38 | if (controls is null)
39 | {
40 | throw new ArgumentNullException(nameof(controls));
41 | }
42 |
43 | if (refFroms is null)
44 | {
45 | throw new ArgumentNullException(nameof(refFroms));
46 | }
47 |
48 | if (classes is null)
49 | {
50 | throw new ArgumentNullException(nameof(classes));
51 | }
52 |
53 | XPrefix = xPrefix;
54 | Xmlns = xmlns;
55 | Controls = controls;
56 | RefFroms = refFroms;
57 | Classes = classes;
58 | }
59 |
60 | public XamlXmlns GetByAlias(string alias)
61 | {
62 | return Xmlns.First(x => x.Alias == alias);
63 | }
64 |
65 | public XamlXmlns? TryGetByNamespace(string @namespace)
66 | {
67 | return Xmlns.FirstOrDefault(x => x.Namespace == @namespace);
68 | }
69 |
70 | public XamlX GetXPrefix()
71 | {
72 | return XPrefix;
73 | }
74 |
75 | public List GetPerformables()
76 | {
77 | var performables = new List();
78 |
79 | performables.AddRange(Controls);
80 | performables.AddRange(RefFroms);
81 | performables.AddRange(Classes);
82 |
83 | return performables;
84 | }
85 |
86 | internal XamlStructure Add(XamlXmlns newXmlns)
87 | {
88 | var xmlns = new List(Xmlns);
89 | xmlns.Add(newXmlns);
90 |
91 | return new XamlStructure(
92 | XPrefix,
93 | xmlns,
94 | Controls,
95 | RefFroms,
96 | Classes
97 | );
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/AdjustNamespace.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33027.239
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "AdjustNamespace.VsixShared", "AdjustNamespace.VsixShared\AdjustNamespace.VsixShared.shproj", "{B8F4DE5D-EEFF-4F14-9C3D-2A6EE41DB482}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdjustNamespace.2022", "AdjustNamespace.2022\AdjustNamespace.2022.csproj", "{E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|arm64 = Debug|arm64
14 | Debug|x86 = Debug|x86
15 | Release|Any CPU = Release|Any CPU
16 | Release|arm64 = Release|arm64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Debug|arm64.ActiveCfg = Debug|Any CPU
23 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Debug|arm64.Build.0 = Debug|Any CPU
24 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Debug|x86.ActiveCfg = Debug|x86
25 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Debug|x86.Build.0 = Debug|x86
26 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Release|arm64.ActiveCfg = Release|Any CPU
29 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Release|arm64.Build.0 = Release|Any CPU
30 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Release|x86.ActiveCfg = Release|x86
31 | {E36D5F78-82AF-4BFE-9147-3D70F51CE1FB}.Release|x86.Build.0 = Release|x86
32 | EndGlobalSection
33 | GlobalSection(SolutionProperties) = preSolution
34 | HideSolutionNode = FALSE
35 | EndGlobalSection
36 | GlobalSection(ExtensibilityGlobals) = postSolution
37 | SolutionGuid = {7332E76C-88D8-4DD6-866A-168626CDF920}
38 | EndGlobalSection
39 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
40 | AdjustNamespace.VsixShared\AdjustNamespace.VsixShared.projitems*{b8f4de5d-eeff-4f14-9c3d-2a6ee41db482}*SharedItemsImports = 13
41 | AdjustNamespace.VsixShared\AdjustNamespace.VsixShared.projitems*{e36d5f78-82af-4bfe-9147-3d70f51ce1fb}*SharedItemsImports = 4
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Авдеев Вячеслав
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Adjust Namespaces
2 |
3 | AdjustNamespace is a Visual Studio 2022 extension which brings the C# namespaces in accordance with the location and **rules the resulting regressions in the code (including XAML), e.g. fixes the broken references**. This extension works like Resharper `Adjust namespaces` function. If you know Resharper, you know what this extension is trying to do.
4 |
5 | ## How to use
6 |
7 | Select object (solution, project, folder or file) in solution explorer, click RMB, choose `Adjust Namespaces...` and follow the wizard.
8 |
9 | 
10 |
11 | or choose the whole solution by this way:
12 |
13 | 
14 |
15 | 
16 |
17 | You can also exclude some folders from participating in namespace chain. AdjustNamepace stores such settings in its configuration xml file, in the folder of your solution. Commit that file to share it across your team.
18 |
19 | ## Remarks
20 |
21 | I test it against plain C# code, WPF Xaml, and C# code from `sqlproj`. I encourage you test against your codebase and report bugs (with minimal repro) to https://github.com/lsoft/AdjustNamespace/issues.
22 |
--------------------------------------------------------------------------------
/Tests/Standard/DatabaseProject/ClassFile1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FakeDatabaseProject
6 | {
7 | class ClassFile1
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Tests/Standard/DatabaseProject/DatabaseProject.sqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | DatabaseProject
7 | 2.0
8 | 4.1
9 | {e3d2aa90-fb0d-410a-b9fe-7efd5ab9fa94}
10 | Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider
11 | Database
12 |
13 |
14 | DatabaseProject
15 | DatabaseProject
16 | 1033, CI
17 | BySchemaAndSchemaType
18 | True
19 | v4.7.2
20 | CS
21 | Properties
22 | False
23 | True
24 | True
25 |
26 |
27 | bin\Release\
28 | $(MSBuildProjectName).sql
29 | False
30 | pdbonly
31 | true
32 | false
33 | true
34 | prompt
35 | 4
36 |
37 |
38 | bin\Debug\
39 | $(MSBuildProjectName).sql
40 | false
41 | true
42 | full
43 | false
44 | true
45 | true
46 | prompt
47 | 4
48 |
49 |
50 | 11.0
51 |
52 | True
53 | 11.0
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/Tests/Standard/DatabaseProject/MyFolder/ClassFile2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FakeDatabaseProject.FakeFolder
6 | {
7 | class ClassFile2
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/App.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace TestMauiApp
2 | {
3 | public partial class App : Application
4 | {
5 | public App()
6 | {
7 | InitializeComponent();
8 |
9 | MainPage = new AppShell();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/AppShell.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/AppShell.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace TestMauiApp
2 | {
3 | public partial class AppShell : Shell
4 | {
5 | public AppShell()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace TestMauiApp
2 | {
3 | public partial class MainPage : ContentPage
4 | {
5 | int count = 0;
6 |
7 | public MainPage()
8 | {
9 | InitializeComponent();
10 | }
11 |
12 | private void OnCounterClicked(object sender, EventArgs e)
13 | {
14 | count++;
15 |
16 | if (count == 1)
17 | CounterBtn.Text = $"Clicked {count} time";
18 | else
19 | CounterBtn.Text = $"Clicked {count} times";
20 |
21 | SemanticScreenReader.Announce(CounterBtn.Text);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/MauiProgram.cs:
--------------------------------------------------------------------------------
1 | namespace TestMauiApp
2 | {
3 | public static class MauiProgram
4 | {
5 | public static MauiApp CreateMauiApp()
6 | {
7 | var builder = MauiApp.CreateBuilder();
8 | builder
9 | .UseMauiApp()
10 | .ConfigureFonts(fonts =>
11 | {
12 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
13 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
14 | });
15 |
16 | return builder.Build();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Android/MainActivity.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content.PM;
3 | using Android.OS;
4 |
5 | namespace TestMauiApp
6 | {
7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8 | public class MainActivity : MauiAppCompatActivity
9 | {
10 | }
11 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Android/MainApplication.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Runtime;
3 |
4 | namespace TestMauiApp
5 | {
6 | [Application]
7 | public class MainApplication : MauiApplication
8 | {
9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10 | : base(handle, ownership)
11 | {
12 | }
13 |
14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
15 | }
16 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #512BD4
4 | #2B0B98
5 | #2B0B98
6 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/MacCatalyst/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 |
3 | namespace TestMauiApp
4 | {
5 | [Register("AppDelegate")]
6 | public class AppDelegate : MauiUIApplicationDelegate
7 | {
8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9 | }
10 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/MacCatalyst/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UIDeviceFamily
6 |
7 | 1
8 | 2
9 |
10 | UIRequiredDeviceCapabilities
11 |
12 | arm64
13 |
14 | UISupportedInterfaceOrientations
15 |
16 | UIInterfaceOrientationPortrait
17 | UIInterfaceOrientationLandscapeLeft
18 | UIInterfaceOrientationLandscapeRight
19 |
20 | UISupportedInterfaceOrientations~ipad
21 |
22 | UIInterfaceOrientationPortrait
23 | UIInterfaceOrientationPortraitUpsideDown
24 | UIInterfaceOrientationLandscapeLeft
25 | UIInterfaceOrientationLandscapeRight
26 |
27 | XSAppIconAssets
28 | Assets.xcassets/appicon.appiconset
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/MacCatalyst/Program.cs:
--------------------------------------------------------------------------------
1 | using ObjCRuntime;
2 | using UIKit;
3 |
4 | namespace TestMauiApp
5 | {
6 | public class Program
7 | {
8 | // This is the main entry point of the application.
9 | static void Main(string[] args)
10 | {
11 | // if you want to use a different Application Delegate class from "AppDelegate"
12 | // you can specify it here.
13 | UIApplication.Main(args, null, typeof(AppDelegate));
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Tizen/Main.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui;
2 | using Microsoft.Maui.Hosting;
3 | using System;
4 |
5 | namespace TestMauiApp
6 | {
7 | internal class Program : MauiApplication
8 | {
9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
10 |
11 | static void Main(string[] args)
12 | {
13 | var app = new Program();
14 | app.Run(args);
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Tizen/tizen-manifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | maui-appicon-placeholder
7 |
8 |
9 |
10 |
11 | http://tizen.org/privilege/internet
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Windows/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Windows/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.UI.Xaml;
2 |
3 | // To learn more about WinUI, the WinUI project structure,
4 | // and more about our project templates, see: http://aka.ms/winui-project-info.
5 |
6 | namespace TestMauiApp.WinUI
7 | {
8 | ///
9 | /// Provides application-specific behavior to supplement the default Application class.
10 | ///
11 | public partial class App : MauiWinUIApplication
12 | {
13 | ///
14 | /// Initializes the singleton application object. This is the first line of authored code
15 | /// executed, and as such is the logical equivalent of main() or WinMain().
16 | ///
17 | public App()
18 | {
19 | this.InitializeComponent();
20 | }
21 |
22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
23 | }
24 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Windows/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | $placeholder$
15 | User Name
16 | $placeholder$.png
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/Windows/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 | true/PM
12 | PerMonitorV2, PerMonitor
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/iOS/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 |
3 | namespace TestMauiApp
4 | {
5 | [Register("AppDelegate")]
6 | public class AppDelegate : MauiUIApplicationDelegate
7 | {
8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9 | }
10 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | LSRequiresIPhoneOS
6 |
7 | UIDeviceFamily
8 |
9 | 1
10 | 2
11 |
12 | UIRequiredDeviceCapabilities
13 |
14 | arm64
15 |
16 | UISupportedInterfaceOrientations
17 |
18 | UIInterfaceOrientationPortrait
19 | UIInterfaceOrientationLandscapeLeft
20 | UIInterfaceOrientationLandscapeRight
21 |
22 | UISupportedInterfaceOrientations~ipad
23 |
24 | UIInterfaceOrientationPortrait
25 | UIInterfaceOrientationPortraitUpsideDown
26 | UIInterfaceOrientationLandscapeLeft
27 | UIInterfaceOrientationLandscapeRight
28 |
29 | XSAppIconAssets
30 | Assets.xcassets/appicon.appiconset
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Platforms/iOS/Program.cs:
--------------------------------------------------------------------------------
1 | using ObjCRuntime;
2 | using UIKit;
3 |
4 | namespace TestMauiApp
5 | {
6 | public class Program
7 | {
8 | // This is the main entry point of the application.
9 | static void Main(string[] args)
10 | {
11 | // if you want to use a different Application Delegate class from "AppDelegate"
12 | // you can specify it here.
13 | UIApplication.Main(args, null, typeof(AppDelegate));
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Windows Machine": {
4 | "commandName": "MsixPackage",
5 | "nativeDebugging": false
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/AppIcon/appicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/AppIcon/appiconfg.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/Fonts/OpenSans-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/Tests/Standard/TestMauiApp/Resources/Fonts/OpenSans-Regular.ttf
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/Fonts/OpenSans-Semibold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/Tests/Standard/TestMauiApp/Resources/Fonts/OpenSans-Semibold.ttf
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/Raw/AboutAssets.txt:
--------------------------------------------------------------------------------
1 | Any raw assets you want to be deployed with your application can be placed in
2 | this directory (and child directories). Deployment of the asset to your application
3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`.
4 |
5 |
6 |
7 | These files will be deployed with you package and will be accessible using Essentials:
8 |
9 | async Task LoadMauiAsset()
10 | {
11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt");
12 | using var reader = new StreamReader(stream);
13 |
14 | var contents = reader.ReadToEnd();
15 | }
16 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/Splash/splash.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/Resources/Styles/Colors.xaml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 | #512BD4
8 | #DFD8F7
9 | #2B0B98
10 | White
11 | Black
12 | #E1E1E1
13 | #C8C8C8
14 | #ACACAC
15 | #919191
16 | #6E6E6E
17 | #404040
18 | #212121
19 | #141414
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | #F7B548
35 | #FFD590
36 | #FFE5B9
37 | #28C2D1
38 | #7BDDEF
39 | #C3F2F4
40 | #3E8EED
41 | #72ACF1
42 | #A7CBF6
43 |
44 |
--------------------------------------------------------------------------------
/Tests/Standard/TestMauiApp/TestMauiApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-android;net6.0-ios;net6.0-maccatalyst
5 | $(TargetFrameworks);net6.0-windows10.0.19041.0
6 |
7 |
8 | Exe
9 | TestMauiApp
10 | true
11 | true
12 | enable
13 |
14 |
15 | TestMauiApp
16 |
17 |
18 | com.companyname.testmauiapp
19 | 82f352d8-6b53-4fc7-aa11-663ef2a55305
20 |
21 |
22 | 1.0
23 | 1
24 |
25 | 14.2
26 | 14.0
27 | 21.0
28 | 10.0.17763.0
29 | 10.0.17763.0
30 | 6.5
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/A/B/C/D/Class1.cs:
--------------------------------------------------------------------------------
1 | namespace fixme;
2 |
3 | class Class1
4 | {
5 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp1/Class123.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | //uncomment this line to see a small defect in AdjustNamespace algorithm: using SubjectWrong;
8 | using SubjectWrong.Exp1;
9 |
10 | namespace SubjectWrong.Exp1
11 | {
12 | internal class Exp1Class1
13 | {
14 | }
15 | }
16 |
17 | namespace Subject.Exp1Wrong
18 | {
19 | internal class Exp1Class2
20 | {
21 | }
22 | }
23 |
24 | namespace SubjectWrong.Exp1Wrong
25 | {
26 | internal class Exp1Class3
27 | {
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp1/Class4.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SubjectWrong.Exp1SubjectWrong;
9 |
10 | internal class Exp1Class4
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp1/Class5.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Subject.Exp1Wrong;
8 |
9 | namespace SubjectWrong.Exp1SubjectWrong2;
10 |
11 | internal class Exp1Class5
12 | {
13 | public Exp1Class5(
14 | SubjectWrong.Exp1.Exp1Class1 p1,
15 | Exp1Class2 p2,
16 | Exp1Wrong.Exp1Class3 p3
17 | )
18 | {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp1/Class67.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Subject.Exp1Wrong;
8 |
9 | namespace SubjectWrong.Exp1SubjectWrong2
10 | {
11 | using AbsoletlyWrong;
12 |
13 | internal class Exp1Class6
14 | {
15 | public Exp1Class6(
16 | SubjectWrong.Exp1.Exp1Class1 p1,
17 | Exp1Class2 p2,
18 | Exp1Wrong.Exp1Class3 p3,
19 | SubjectWrong.Exp1SubjectWrong2.AbsoletlyWrong.Exp1Class7 p7_1,
20 | Exp1SubjectWrong2.AbsoletlyWrong.Exp1Class7 p7_2,
21 | AbsoletlyWrong.Exp1Class7 p7_3,
22 | Exp1Class7 p7_4
23 | )
24 | {
25 | }
26 | }
27 |
28 | namespace AbsoletlyWrong
29 | {
30 | internal class Exp1Class7
31 | {
32 | public Exp1Class7(
33 | SubjectWrong.Exp1.Exp1Class1 p1,
34 | Exp1Class2 p2,
35 | Exp1Wrong.Exp1Class3 p3,
36 | SubjectWrong.Exp1SubjectWrong2.Exp1Class5 p5_1,
37 | Exp1SubjectWrong2.Exp1Class5 p5_2,
38 | Exp1Class5 p5_3
39 | )
40 | {
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp10/MyClass.cs:
--------------------------------------------------------------------------------
1 | namespace SubjectWrong.Exp10
2 | {
3 | public class MyClass : Typed
4 | {
5 |
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp10/Nested.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SubjectWrong.Exp10
8 | {
9 | public class Nested
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp10/Typed.cs:
--------------------------------------------------------------------------------
1 | namespace SubjectWrong.Exp10
2 | {
3 | public abstract class Typed : Nested
4 | where RowT : Nested
5 | {
6 |
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp11/Folder1/Nested.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SubjectWrong.Exp11.Folder1
8 | {
9 | public class Nested
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp11/Folder2/MyClass12.cs:
--------------------------------------------------------------------------------
1 | namespace TestProject.Exp11.Folder2
2 | {
3 | using SubjectWrong.Exp11.Folder1;
4 |
5 | public class MyClass1 : Typed1
6 | {
7 |
8 | }
9 | }
10 |
11 | namespace TestProject.Exp11.Folder2
12 | {
13 | public class MyClass2 : Typed2
14 | {
15 |
16 | }
17 | }
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp11/Folder2/Typed12.cs:
--------------------------------------------------------------------------------
1 | namespace TestProject.Exp11.Folder2
2 | {
3 | public abstract class Typed1 : SubjectWrong.Exp11.Folder1.Nested
4 | where RowT : SubjectWrong.Exp11.Folder1.Nested
5 | {
6 |
7 | }
8 | }
9 |
10 | namespace TestProject.Exp11.Folder2
11 | {
12 | public abstract class Typed2 : SubjectWrong.Exp11.Folder1.Nested
13 | where RowT : SubjectWrong.Exp11.Folder1.Nested
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp12/Class1/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace TestProject.Exp12
8 | {
9 | internal class Class1
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp12/Class2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace TestProject.Exp12
8 | {
9 | internal class Class2
10 | {
11 | public Class1 MyClass;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp13/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace TestProject.Exp13
8 | {
9 | internal class Class1
10 | {
11 | Exp13 Field;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp13/Exp13/Exp13.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace TestProject.Exp13
8 | {
9 | internal class Exp13
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp2/Class1.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SubjectWrong.Exp2;
9 |
10 | internal class Class1
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp2/Class2.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace TestProject.Exp2
9 | {
10 | internal class Class2 : SubjectWrong.Exp2.Class1
11 | {
12 | }
13 | }
14 |
15 | namespace TestProject.Exp2
16 | {
17 | using SubjectWrong.Exp2;
18 |
19 | internal class Class3 : Class1
20 | {
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp3/Class1.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SubjectWrong.Exp3
9 | {
10 | internal class Class1
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp3/Class23456.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace TestProject.Exp3
9 | {
10 | internal class Class2
11 | {
12 | }
13 | }
14 |
15 | namespace TestProject.Exp3
16 | {
17 | internal class Class3 : Class2
18 | {
19 | }
20 | }
21 |
22 | namespace TestProject.Exp3
23 | {
24 | using SubjectWrong.Exp3;
25 |
26 | internal class Class4 : Class2
27 | {
28 | }
29 | }
30 |
31 | namespace TestProject.Exp3
32 | {
33 | internal class Class5 : Class2
34 | where T : SubjectWrong.Exp3.Class1
35 | {
36 | }
37 | }
38 |
39 | namespace TestProject.Exp3
40 | {
41 | using SubjectWrong.Exp3;
42 |
43 | internal class Class6 : Class2
44 | where T : Class1
45 | {
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp4/Class1.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SubjectWrong.Exp4
9 | {
10 | internal enum MyEnum
11 | {
12 | MustBeCrossCluster
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp4/Class23.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0001, IDE0005
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace TestProject.Exp4
9 | {
10 | internal class Class2
11 | {
12 | public SubjectWrong.Exp4.MyEnum Setting => SubjectWrong.Exp4.MyEnum.MustBeCrossCluster;
13 | }
14 | }
15 |
16 | namespace TestProject.Exp4
17 | {
18 | using SubjectWrong.Exp4;
19 |
20 | internal class Class3
21 | {
22 | public MyEnum Setting => MyEnum.MustBeCrossCluster;
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SubjectWrong.Exp5
8 | {
9 | internal class Class1
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl1.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl1.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace SubjectWrong.Exp5
17 | {
18 | ///
19 | /// Interaction logic for UserControl1.xaml
20 | ///
21 | public partial class UserControl1 : UserControl
22 | {
23 | public static string StaticString = "do not delete";
24 |
25 | public UserControl1()
26 | {
27 | InitializeComponent();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl2.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl2.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace TestProject.Exp5
17 | {
18 | ///
19 | /// Interaction logic for UserControl2.xaml
20 | ///
21 | public partial class UserControl2 : UserControl
22 | {
23 | public UserControl2()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl3.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl3.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace SubjectWrong.Exp5
17 | {
18 | ///
19 | /// Interaction logic for UserControl3.xaml
20 | ///
21 | public partial class UserControl3 : UserControl
22 | {
23 | public UserControl3()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl4.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl4.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace SubjectWrong.Exp5
17 | {
18 | ///
19 | /// Interaction logic for UserControl4.xaml
20 | ///
21 | public partial class UserControl4 : ListBox
22 | {
23 | public UserControl4()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl5.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl5.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace TestProject.Exp5
17 | {
18 | ///
19 | /// Interaction logic for UserControl5.xaml
20 | ///
21 | public partial class UserControl5 : UserControl
22 | {
23 | public UserControl5()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl6.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp5/UserControl6.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace TestProject.Exp5
17 | {
18 | ///
19 | /// Interaction logic for UserControl6.xaml
20 | ///
21 | public partial class UserControl6 : UserControl
22 | {
23 | public UserControl6()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp6/Class1234.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SubjectWrong.Exp6
8 | {
9 | internal class Class1
10 | {
11 | internal class Class2
12 | {
13 | internal class Class3
14 | {
15 | internal class Class4
16 | {
17 | }
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp6/Class5.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SubjectWrong.Exp6
8 | {
9 | internal class Class5
10 | {
11 | public Class5(
12 | SubjectWrong.Exp6.Class1 arg
13 | )
14 | {
15 |
16 | }
17 |
18 | public Class5(
19 | SubjectWrong.Exp6.Class1.Class2 arg,
20 | bool _
21 | )
22 | {
23 |
24 | }
25 |
26 | public Class5(
27 | Class1.Class2 arg
28 | )
29 | {
30 |
31 | }
32 |
33 |
34 | public Class5(
35 | SubjectWrong.Exp6.Class1.Class2.Class3 arg,
36 | bool _
37 | )
38 | {
39 |
40 | }
41 |
42 | public Class5(
43 | Class1.Class2.Class3 arg
44 | )
45 | {
46 |
47 | }
48 |
49 | public Class5(
50 | SubjectWrong.Exp6.Class1.Class2.Class3.Class4 arg,
51 | bool _
52 | )
53 | {
54 |
55 | }
56 |
57 | public Class5(
58 | Class1.Class2.Class3.Class4 arg
59 | )
60 | {
61 |
62 | }
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp7/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace System.Runtime.CompilerServices
8 | {
9 | sealed class CallerMemberNameAttribute : Attribute { }
10 | }
11 |
12 | namespace TestProject.Exp7
13 | {
14 | internal class Class1
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp8/FakeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace System.Runtime.CompilerServices
8 | {
9 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
10 | internal class FakeAttribute : Attribute
11 | {
12 | }
13 |
14 | }
15 |
16 | namespace TestProject.Exp8
17 | {
18 |
19 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
20 | internal class FakeAttribute : Attribute
21 | {
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Exp9/Class100.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace System.Runtime.CompilerServices
8 | {
9 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
10 | internal class Fake2Attribute : Attribute
11 | {
12 | }
13 |
14 | }
15 |
16 | namespace TestProject.Exp7
17 | {
18 |
19 | internal class Class100
20 | {
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Subject
4 | {
5 | internal class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Console.WriteLine("Hello World!");
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Tests/Standard/TestProject/TestProject.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0-windows
6 | true
7 | true
8 | Latest
9 |
10 |
11 |
12 |
13 | Code
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Tests/Standard/TestSharedProject/SharedClass1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FakeNamespace
6 | {
7 | internal class SharedClass1
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Tests/Standard/TestSharedProject/SharedFolder/SharedClass2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FakeNamespace.SharedFolder
6 | {
7 | internal class SharedClass2
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Tests/Standard/TestSharedProject/TestSharedProject.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | cd802bc9-8f39-412c-9929-4536b0ead347
7 |
8 |
9 | TestSharedNamespace
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Tests/Standard/TestSharedProject/TestSharedProject.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | cd802bc9-8f39-412c-9929-4536b0ead347
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Tests/Standard/TestSolution.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33027.239
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject", "TestProject\TestProject.csproj", "{C58A4EE1-4B9A-458C-8251-373D3BCC0D6E}"
7 | EndProject
8 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "DatabaseProject", "DatabaseProject\DatabaseProject.sqlproj", "{E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NewFolder1", "NewFolder1", "{5D243CC9-770E-4A16-9F6F-4FB13C463803}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NewFolder2", "NewFolder2", "{877DB1BD-DBBB-4997-9B26-EBA7518D5FE1}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NewFolder3", "NewFolder3", "{426939EF-91E0-40F4-B093-11682B5B6469}"
15 | EndProject
16 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "TestSharedProject", "TestSharedProject\TestSharedProject.shproj", "{CD802BC9-8F39-412C-9929-4536B0EAD347}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestMauiApp", "TestMauiApp\TestMauiApp.csproj", "{629C7607-BF79-4449-9808-859D31207304}"
19 | EndProject
20 | Global
21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 | Debug|Any CPU = Debug|Any CPU
23 | Release|Any CPU = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {C58A4EE1-4B9A-458C-8251-373D3BCC0D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {C58A4EE1-4B9A-458C-8251-373D3BCC0D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {C58A4EE1-4B9A-458C-8251-373D3BCC0D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {C58A4EE1-4B9A-458C-8251-373D3BCC0D6E}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
33 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}.Release|Any CPU.Build.0 = Release|Any CPU
35 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94}.Release|Any CPU.Deploy.0 = Release|Any CPU
36 | {629C7607-BF79-4449-9808-859D31207304}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {629C7607-BF79-4449-9808-859D31207304}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {629C7607-BF79-4449-9808-859D31207304}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
39 | {629C7607-BF79-4449-9808-859D31207304}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {629C7607-BF79-4449-9808-859D31207304}.Release|Any CPU.Build.0 = Release|Any CPU
41 | {629C7607-BF79-4449-9808-859D31207304}.Release|Any CPU.Deploy.0 = Release|Any CPU
42 | EndGlobalSection
43 | GlobalSection(SolutionProperties) = preSolution
44 | HideSolutionNode = FALSE
45 | EndGlobalSection
46 | GlobalSection(NestedProjects) = preSolution
47 | {C58A4EE1-4B9A-458C-8251-373D3BCC0D6E} = {877DB1BD-DBBB-4997-9B26-EBA7518D5FE1}
48 | {E3D2AA90-FB0D-410A-B9FE-7EFD5AB9FA94} = {426939EF-91E0-40F4-B093-11682B5B6469}
49 | {877DB1BD-DBBB-4997-9B26-EBA7518D5FE1} = {5D243CC9-770E-4A16-9F6F-4FB13C463803}
50 | {426939EF-91E0-40F4-B093-11682B5B6469} = {877DB1BD-DBBB-4997-9B26-EBA7518D5FE1}
51 | {CD802BC9-8F39-412C-9929-4536B0EAD347} = {5D243CC9-770E-4A16-9F6F-4FB13C463803}
52 | EndGlobalSection
53 | GlobalSection(ExtensibilityGlobals) = postSolution
54 | SolutionGuid = {AE24893F-C804-40AF-BE98-551D4E1E79D9}
55 | EndGlobalSection
56 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
57 | TestSharedProject\TestSharedProject.projitems*{c58a4ee1-4b9a-458c-8251-373d3bcc0d6e}*SharedItemsImports = 5
58 | TestSharedProject\TestSharedProject.projitems*{cd802bc9-8f39-412c-9929-4536b0ead347}*SharedItemsImports = 13
59 | EndGlobalSection
60 | EndGlobal
61 |
--------------------------------------------------------------------------------
/Tests/Standard/adjust_namespaces_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | C:\projects\github\AdjustNamespace\Tests\Subject\TestProject\A\B\C\
5 | TestProject\A\B
6 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/demo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/demo1.png
--------------------------------------------------------------------------------
/demo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/demo2.png
--------------------------------------------------------------------------------
/demo3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsoft/AdjustNamespace/23be192e706275cc0b66203999431052d3e170f7/demo3.png
--------------------------------------------------------------------------------