Skip to content

Commit

Permalink
Seal internal types (microsoft#677)
Browse files Browse the repository at this point in the history
### Motivation and Context
Seal internal types.

### Description

These would normally be flagged by CA1852, but it's currently unable to
handle assemblies marked as InternalsVisibleTo, and all of these
assemblies are. Sealing internal types is generally a good practice as
a) it can always be changed so there's little downside, b) it can help
to communicate to elsewhere in the project whether the type is intended
to be derived from (just as using visibility on members communicates
what should / shouldn't be used), and c) it can help with performance in
some situations, especially on .NET Core.
  • Loading branch information
stephentoub committed Apr 26, 2023
1 parent 82a5c64 commit 90b713c
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/Connectors/Connectors.Memory.Sqlite/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal struct DatabaseEntry
public string? Timestamp { get; set; }
}

internal class Database
internal sealed class Database
{
private const string TableName = "SKMemoryTable";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.SemanticKernel.Connectors.WebApi.Rest.Model;
/// <summary>
/// The REST API operation.
/// </summary>
internal class RestApiOperation
internal sealed class RestApiOperation
{
/// <summary>
/// An artificial parameter that is added to be able to override RESP API operation server url.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.SemanticKernel.Connectors.WebApi.Rest.Model;
/// <summary>
/// The REST API operation parameter.
/// </summary>
internal class RestApiOperationParameter
internal sealed class RestApiOperationParameter
{
/// <summary>
/// The parameter name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.SemanticKernel.Connectors.WebApi.Rest.Model;
/// <summary>
/// The REST API operation payload property.
/// </summary>
internal class RestApiOperationPayloadProperty
internal sealed class RestApiOperationPayloadProperty
{
/// <summary>
/// The property name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.SemanticKernel.Connectors.WebApi.Rest;
/// <summary>
/// Runs REST API operation represented by RestApiOperation model class.
/// </summary>
internal class RestApiOperationRunner : IRestApiOperationRunner
internal sealed class RestApiOperationRunner : IRestApiOperationRunner
{
private const string MediaTypeApplicationJson = "application/json";
private const string MediaTypeTextPlain = "text/plain";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal interface IDelayProvider
Task DelayAsync(TimeSpan delay, CancellationToken cancellationToken);
}

internal class TaskDelayProvider : IDelayProvider
internal sealed class TaskDelayProvider : IDelayProvider
{
public Task DelayAsync(TimeSpan delay, CancellationToken cancellationToken)
{
Expand All @@ -152,7 +152,7 @@ internal interface ITimeProvider
DateTimeOffset GetCurrentTime();
}

internal class DefaultTimeProvider : ITimeProvider
internal sealed class DefaultTimeProvider : ITimeProvider
{
public DateTimeOffset GetCurrentTime()
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/SemanticKernel/CoreSkills/WaitSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IWaitProvider
Task DelayAsync(int milliSeconds);
}

private class WaitProvider : IWaitProvider
private sealed class WaitProvider : IWaitProvider
{
public Task DelayAsync(int milliSeconds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.SemanticKernel.SkillDefinition;
/// <summary>
/// Access the collection in read-only mode, e.g. allow templates to search and execute functions.
/// </summary>
internal class ReadOnlySkillCollection : IReadOnlySkillCollection
internal sealed class ReadOnlySkillCollection : IReadOnlySkillCollection
{
private readonly ISkillCollection _skillCollection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.SemanticKernel.TemplateEngine.Blocks;

#pragma warning disable CA2254 // error strings are used also internally, not just for logging
// ReSharper disable TemplateIsNotCompileTimeConstantProblem
internal class CodeBlock : Block, ICodeRendering
internal sealed class CodeBlock : Block, ICodeRendering
{
internal override BlockTypes Type => BlockTypes.Code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.SemanticKernel.TemplateEngine.Blocks;

internal class FunctionIdBlock : Block, ITextRendering
internal sealed class FunctionIdBlock : Block, ITextRendering
{
internal override BlockTypes Type => BlockTypes.FunctionId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.SemanticKernel.TemplateEngine.Blocks;

internal class TextBlock : Block, ITextRendering
internal sealed class TextBlock : Block, ITextRendering
{
internal override BlockTypes Type => BlockTypes.Text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.SemanticKernel.TemplateEngine.Blocks;

internal class ValBlock : Block, ITextRendering
internal sealed class ValBlock : Block, ITextRendering
{
internal override BlockTypes Type => BlockTypes.Value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.SemanticKernel.TemplateEngine.Blocks;

internal class VarBlock : Block, ITextRendering
internal sealed class VarBlock : Block, ITextRendering
{
internal override BlockTypes Type => BlockTypes.Variable;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/SemanticKernel/TemplateEngine/CodeTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Microsoft.SemanticKernel.TemplateEngine;
/// [letter] ::= "a" | "b" ... | "z" | "A" | "B" ... | "Z"
/// [digit] ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
/// </summary>
internal class CodeTokenizer
internal sealed class CodeTokenizer
{
private enum TokenTypes
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Microsoft.SemanticKernel.TemplateEngine;
/// [letter] ::= "a" | "b" ... | "z" | "A" | "B" ... | "Z"
/// [digit] ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
/// </summary>
internal class TemplateTokenizer
internal sealed class TemplateTokenizer
{
/// <summary>
/// Create a new instance of SK tokenizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.SemanticKernel.Skills.OpenAPI.OpenApi;
/// <summary>
/// Parser for OpenAPI documents.
/// </summary>
internal class OpenApiDocumentParser : IOpenApiDocumentParser
internal sealed class OpenApiDocumentParser : IOpenApiDocumentParser
{
/// <inheritdoc/>
public async Task<IList<RestApiOperation>> ParseAsync(Stream stream, CancellationToken cancellationToken = default)
Expand Down

0 comments on commit 90b713c

Please sign in to comment.