Skip to content

Commit

Permalink
Use C# 12 collection initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Prosperi committed Dec 12, 2023
1 parent 655e331 commit c7ba022
Show file tree
Hide file tree
Showing 56 changed files with 104 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net8.0-windows8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/azure-public/vside/_packaging/msft_consumption/nuget/v3/index.json;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ internal static class ExtensionCommandConfiguration
[VisualStudioContribution]
public static ToolbarConfiguration ToolBar => new("%CommandParentingSample.ToolBar.DisplayName%")
{
Children = new[]
{
Children =
[
ToolbarChild.Command<SampleCommand>(),
},
],
};
}
12 changes: 6 additions & 6 deletions New_Extensibility_Model/Samples/CommandParentingSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ The `CommandConfiguration` property defines information about the command that a
```csharp
public override CommandConfiguration CommandConfiguration => new("%CommandParentingSample.SampleCommand.DisplayName%")
{
Placements = new[]
{
Placements =
[
// File in project context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 521, priority: 0),

Expand All @@ -38,7 +38,7 @@ The `CommandConfiguration` property defines information about the command that a

// Solution context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 537, priority: 0),
},
],
};
```

Expand All @@ -54,10 +54,10 @@ The `ToolbarConfiguration` property defines information about the toolbar that a
[VisualStudioContribution]
public static ToolbarConfiguration ToolBar => new("%CommandParentingSample.ToolBar.DisplayName%")
{
Children = new[]
{
Children =
[
ToolbarChild.Command<SampleCommand>(),
},
],
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ internal class SampleCommand : Command
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%CommandParentingSample.SampleCommand.DisplayName%")
{
Placements = new[]
{
// File in project context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 521, priority: 0),

// Project context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 518, priority: 0),

// Solution context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 537, priority: 0),
},
Placements =
[
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 521, priority: 0), // File in project context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 518, priority: 0), // Project context menu
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 537, priority: 0), // Solution context menu
],
};

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net472</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NoWarn>$(NoWarn);SA1633</NoWarn>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal abstract class CommentRemoverCommand : Microsoft.VisualStudio.Extensibi
{
protected static readonly ActivationConstraint CommandEnabledWhen = ActivationConstraint.ClientContext(ClientContextKey.Shell.ActiveSelectionFileName, @"\.(cs|vb|fs)$");

private static readonly string[] TaskCaptions = { "TODO", "HACK", "UNDONE", "UNRESOLVEDMERGECONFLICT" };
private static readonly string[] TaskCaptions = ["TODO", "HACK", "UNDONE", "UNRESOLVEDMERGECONFLICT"];

public CommentRemoverCommand(
TraceSource traceSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ internal static class ExtensionCommandConfiguration
[VisualStudioContribution]
public static MenuConfiguration CommentRemoverMenu => new("%CommentRemover.CommentRemoverMenu.DisplayName%")
{
Placements = new[]
{
Placements =
[
CommandPlacement.KnownPlacements.ExtensionsMenu.WithPriority(0x01),
},
Children = new[]
{
],
Children =
[
MenuChild.Command<RemoveAllComments>(),
MenuChild.Command<RemoveXmlDocComments>(),
MenuChild.Command<RemoveAllExceptXmlDocComments>(),
Expand All @@ -22,6 +22,6 @@ internal static class ExtensionCommandConfiguration
MenuChild.Command<RemoveAllExceptTaskComments>(),
MenuChild.Separator,
MenuChild.Command<RemoveRegions>(),
},
],
};
}
14 changes: 7 additions & 7 deletions New_Extensibility_Model/Samples/CommentRemover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class RemoveAllComments : CommentRemoverCommand
{
Icon = new(ImageMoniker.KnownValues.Uncomment, IconSettings.IconAndText),
EnabledWhen = CommandEnabledWhen,
Shortcuts = new[] { new CommandShortcutConfiguration(ModifierKey.Control, Key.K, ModifierKey.Control, Key.Q) },
Shortcuts = [new CommandShortcutConfiguration(ModifierKey.Control, Key.K, ModifierKey.Control, Key.Q)],
};

public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
Expand All @@ -57,12 +57,12 @@ internal static class ExtensionCommandConfiguration
[VisualStudioContribution]
public static MenuConfiguration CommentRemoverMenu => new("%CommentRemover.CommentRemoverMenu.DisplayName%")
{
Placements = new[]
{
Placements =
[
CommandPlacement.KnownPlacements.ExtensionsMenu.WithPriority(0x01),
},
Children = new[]
{
],
Children =
[
MenuChild.Command<RemoveAllComments>(),
MenuChild.Command<RemoveXmlDocComments>(),
MenuChild.Command<RemoveAllExceptXmlDocComments>(),
Expand All @@ -71,7 +71,7 @@ internal static class ExtensionCommandConfiguration
MenuChild.Command<RemoveAllExceptTaskComments>(),
MenuChild.Separator,
MenuChild.Command<RemoveRegions>(),
},
],
};
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RemoveAllComments(
{
Icon = new(ImageMoniker.KnownValues.Uncomment, IconSettings.IconAndText),
EnabledWhen = CommandEnabledWhen,
Shortcuts = new[] { new CommandShortcutConfiguration(ModifierKey.Control, Key.K, ModifierKey.Control, Key.Q) },
Shortcuts = [new CommandShortcutConfiguration(ModifierKey.Control, Key.K, ModifierKey.Control, Key.Q)],
};

public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MyDialogCommand : Command
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%DialogSample.MyDialogCommand.DisplayName%")
{
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu },
Placements = [CommandPlacement.KnownPlacements.ToolsMenu],
Icon = new(ImageMoniker.KnownValues.Dialog, IconSettings.IconAndText),
};

Expand Down
2 changes: 1 addition & 1 deletion New_Extensibility_Model/Samples/DialogSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The `CommandConfiguration` property defines information about the command that a
```csharp
public override CommandConfiguration CommandConfiguration => new("%DialogSample.MyDialogCommand.DisplayName%")
{
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu },
Placements = [CommandPlacement.KnownPlacements.ToolsMenu],
Icon = new(ImageMoniker.KnownValues.Dialog, IconSettings.IconAndText),
};
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The extension emulates running unit tests on background when user opens any C# f
/// <inheritdoc />
public TextViewExtensionConfiguration TextViewExtensionConfiguration => new()
{
AppliesTo = new[]
{
DocumentFilter.FromGlobPattern("**/tests/*.cs", relativePath: false),
},
AppliesTo =
[
DocumentFilter.FromGlobPattern("**/tests/*.cs", relativePath: false),
],
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public UnitTestRunner(Extension extension, VisualStudioExtensibility extensibili
/// <inheritdoc />
public TextViewExtensionConfiguration TextViewExtensionConfiguration => new()
{
AppliesTo = new[]
{
AppliesTo =
[
DocumentFilter.FromGlobPattern("**/tests/*.cs", relativePath: false),
},
],
};

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public EditorMarginTest(VisualStudioExtensibility extensibility)
[VisualStudioContribution]
public static DocumentTypeConfiguration WordsDocumentType => new(FileExtension)
{
FileExtensions = new[] { "." + FileExtension },
FileExtensions = ["." + FileExtension],
BaseDocumentType = DocumentType.KnownValues.Text,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ internal class WordCountMarginProvider : ExtensionPart, ITextViewMarginProvider,
/// <inheritdoc />
public TextViewExtensionConfiguration TextViewExtensionConfiguration => new()
{
AppliesTo = new[]
{
AppliesTo =
[
DocumentFilter.FromDocumentType(EditorMarginTest.WordsDocumentType),
},
],
};

/// <inheritdoc />
public TextViewMarginProviderConfiguration TextViewMarginProviderConfiguration =>
new(marginContainer: ContainerMarginPlacement.KnownValues.BottomRightCorner)
{
Before = new[] { MarginPlacement.KnownValues.RowMargin },
Before = [MarginPlacement.KnownValues.RowMargin],
};

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LanguageServerTest(VisualStudioExtensibility extensibility)
#pragma warning disable VSEXTAPI0001 // This API is marked as Preview.
public static DocumentTypeConfiguration TodosDocumentType => new(FileExtension)
{
FileExtensions = new[] { "." + FileExtension },
FileExtensions = ["." + FileExtension],
BaseDocumentType = LanguageServerProvider.LanguageServerBaseDocumentType,
};
#pragma warning restore VSEXTAPI0001 // This API is marked as Preview.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ internal class TodoLanguageServerProvider : LanguageServerProvider
#else
"%FeatureGallery.LanguageServer.TodoLanguageServerProvider.DisplayName%",
#endif
new[]
{
DocumentFilter.FromDocumentType(LanguageServerTest.TodosDocumentType),
});
[DocumentFilter.FromDocumentType(LanguageServerTest.TodosDocumentType)]);

/// <inheritdoc/>
public override Task<IDuplexPipe?> CreateServerConnectionAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public MainToolWindowCommand()
new("%FeatureGallery.MainToolWindowCommand.DisplayName%")
#endif
{
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu],
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public InsertGuidCommand(TraceSource traceSource)
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%InsertGuid.InsertGuidCommand.DisplayName%")
{
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu],
Icon = new(ImageMoniker.KnownValues.OfficeWebExtension, IconSettings.IconAndText),
VisibleWhen = ActivationConstraint.ClientContext(ClientContextKey.Shell.ActiveEditorContentType, ".+"),
ClientContexts = new[] { "Editor", "Shell" },
ClientContexts = ["Editor", "Shell"],
};

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion New_Extensibility_Model/Samples/InsertGuid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The `CommandConfiguration` property defines information about the command that a
```csharp
public override CommandConfiguration CommandConfiguration => new("%InsertGuid.InsertGuidCommand.DisplayName%")
{
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu],
Icon = new(ImageMoniker.KnownValues.OfficeWebExtension, IconSettings. IconAndText),
VisibleWhen = ActivationConstraint.ClientContext(ClientContextKey.Shell.ActiveEditorContentType, ".+"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>

<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed -->
Expand Down
6 changes: 3 additions & 3 deletions New_Extensibility_Model/Samples/MarkdownLinter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ The extension part also utilizes the `AppliesTo` configuration to indicate that
```csharp
public TextViewExtensionConfiguration TextViewExtensionConfiguration => new()
{
AppliesTo = new[]
{
AppliesTo =
[
DocumentFilter.FromGlobPattern("**/*.md", true),
},
],
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RunLinterOnCurrentFileCommand(TraceSource traceSource, MarkdownDiagnostic
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%MarkdownLinter.RunLinterOnCurrentFileCommand.DisplayName%")
{
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu },
Placements = [CommandPlacement.KnownPlacements.ToolsMenu],
Icon = new(ImageMoniker.Custom("MarkdownIcon"), IconSettings.IconAndText),
EnabledWhen = ActivationConstraint.ClientContext(ClientContextKey.Shell.ActiveSelectionFileName, ".+"),
};
Expand All @@ -56,7 +56,7 @@ public override async Task ExecuteCommandAsync(IClientContext context, Cancellat
try
{
// Get the selected item URIs from IDE context that represents the state when command was executed.
var selectedItemPaths = new Uri[] { await context.GetSelectedPathAsync(cancellationToken) };
Uri[] selectedItemPaths = [await context.GetSelectedPathAsync(cancellationToken)];

// Enumerate through each selection and run linter on each selected item.
foreach (var selectedItem in selectedItemPaths.Where(p => p.IsFile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public RunLinterOnSolutionCommand(TraceSource traceSource, MarkdownDiagnosticsSe
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%MarkdownLinter.RunLinterOnSolutionCommand.DisplayName%")
{
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu },
Placements = [CommandPlacement.KnownPlacements.ToolsMenu],
Icon = new(ImageMoniker.Custom("MarkdownIcon"), IconSettings.IconAndText),
EnabledWhen = ActivationConstraint.SolutionState(SolutionState.FullyLoaded),
};
Expand Down
Loading

0 comments on commit c7ba022

Please sign in to comment.