-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created wrappers for Visual Studio's font and color classes.
- Loading branch information
Showing
21 changed files
with
1,735 additions
and
21 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...oolkit/Community.VisualStudio.Toolkit.Shared/Attributes/ProvideFontsAndColorsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace Community.VisualStudio.Toolkit | ||
{ | ||
/// <summary> | ||
/// Registers font and color definitions in Visual Studio. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class ProvideFontsAndColorsAttribute : ProvideServiceAttributeBase | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ProvideFontsAndColorsAttribute"/> class. | ||
/// The <paramref name="providerType"/> will also be provided as a service. | ||
/// </summary> | ||
/// <param name="providerType">The type of the <see cref="BaseFontAndColorProvider"/> implementation to provide.</param> | ||
public ProvideFontsAndColorsAttribute(Type providerType) | ||
: base(providerType, "Services") | ||
{ | ||
ProviderType = providerType; | ||
} | ||
|
||
/// <summary> | ||
/// The <see cref="BaseFontAndColorProvider"/> implementation to provide. | ||
/// </summary> | ||
public Type ProviderType { get; } | ||
|
||
/// <inheritdoc/> | ||
public override void Register(RegistrationContext context) | ||
{ | ||
if (context is not null) | ||
{ | ||
foreach (Type categoryType in BaseFontAndColorProvider.GetCategoryTypes(ProviderType)) | ||
{ | ||
using (Key key = context.CreateKey($"FontAndColors\\{categoryType.FullName}")) | ||
{ | ||
key.SetValue("Category", categoryType.GUID.ToString("B")); | ||
key.SetValue("Package", ProviderType.GUID.ToString("B")); | ||
} | ||
} | ||
} | ||
|
||
base.Register(context); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void Unregister(RegistrationContext context) | ||
{ | ||
if (context is not null) | ||
{ | ||
foreach (Type categoryType in BaseFontAndColorProvider.GetCategoryTypes(ProviderType)) | ||
{ | ||
context.RemoveKey($"FontAndColors\\{categoryType.FullName}"); | ||
} | ||
} | ||
|
||
base.Unregister(context); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/toolkit/Community.VisualStudio.Toolkit.Shared/CodeAnalysis/MemberNotNullAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace System.Diagnostics.CodeAnalysis | ||
{ | ||
/// <summary> | ||
/// This is a copy of the attribute of the same name from .NET 5+ to allow it to be used in .NET Framework. | ||
/// https://github.com/dotnet/runtime/blob/47071da67320985a10f4b70f50f894ab411f4994/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs#L137 | ||
/// </summary> | ||
internal class MemberNotNullAttribute : Attribute | ||
{ | ||
public MemberNotNullAttribute(string member) => Members = new[] { member }; | ||
public MemberNotNullAttribute(params string[] members) => Members = members; | ||
public string[] Members { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.