Skip to content

Commit

Permalink
Code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarciarubio committed Oct 16, 2024
1 parent 7cd1c64 commit fb1a345
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*.cs]

# IDE0008: Use explicit type
csharp_style_var_elsewhere = false

# IDE0008: Use explicit type
csharp_style_var_for_built_in_types = false
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Microsoft.Extensions.Hosting;
#pragma warning restore IDE0130 // Namespace does not match folder structure

// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace System.Diagnostics;
#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace System.Diagnostics;
#pragma warning restore IDE0130 // Namespace does not match folder structure

/// <summary>
/// Options for creating an <see cref="ActivitySource"/>.
Expand All @@ -15,11 +17,7 @@ public string Name
get => _name;
set
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}

ArgumentNullException.ThrowIfNull(value, nameof(Name));
_name = value;
}
}
Expand All @@ -40,8 +38,7 @@ public string Name
/// <param name="name">The ActivitySource name.</param>
public ActivitySourceOptions(string name)
{
Name = name;

Debug.Assert(_name is not null);
ArgumentNullException.ThrowIfNull(name, nameof(name));
_name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Microsoft.Extensions.Hosting;

#pragma warning restore IDE0130 // Namespace does not match folder structure
public static class Extensions
{
private static readonly Type TelemetryType = typeof(Telemetry<>);
Expand Down Expand Up @@ -57,7 +58,7 @@ private static IServiceCollection AddTelemetryInternal<TService>(this IServiceCo
private static bool TryGetBaseTelemetryType(this Type implementationType, [MaybeNullWhen(returnValue: false)] out Type baseTelemetryType)
{
baseTelemetryType = null;
var type = implementationType;
Type? type = implementationType;
while (type != null && type != typeof(object))
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == TelemetryType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.Extensions.Logging;
using System.Diagnostics.Metrics;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace System.Diagnostics;
#pragma warning restore IDE0130 // Namespace does not match folder structure

public interface ITelemetry<out TCategoryName>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using Microsoft.Extensions.Logging;
using System.Diagnostics.Metrics;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace System.Diagnostics;
#pragma warning restore IDE0130 // Namespace does not match folder structure

public class Telemetry<TCategoryName> : ITelemetry<TCategoryName>
public class Telemetry<TCategoryName> : ITelemetry<TCategoryName>, IDisposable
{
private bool disposedValue;

Expand All @@ -21,8 +23,8 @@ public Telemetry(ILoggerFactory loggerFactory, IMeterFactory meterFactory)
public ActivitySource ActivitySource { get; }
public Meter Meter { get; }

protected virtual ActivitySourceOptions ActivitySourceOptions => new ActivitySourceOptions(CategoryName);
protected virtual MeterOptions MeterOptions => new MeterOptions(CategoryName);
protected virtual ActivitySourceOptions ActivitySourceOptions => new(CategoryName);
protected virtual MeterOptions MeterOptions => new(CategoryName);

protected virtual void Dispose(bool disposing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class TypeNameHelper
{
private const char DefaultNestedTypeDelimiter = '+';

private static readonly Dictionary<Type, string> _builtInTypeNames = new Dictionary<Type, string>
private static readonly Dictionary<Type, string> _builtInTypeNames = new()
{
{ typeof(void), "void" },
{ typeof(bool), "bool" },
Expand Down Expand Up @@ -177,22 +177,14 @@ private static void ProcessGenericType(StringBuilder builder, Type type, Type[]
}
}

private readonly struct DisplayNameOptions
private readonly struct DisplayNameOptions(bool fullName, bool includeGenericParameterNames, bool includeGenericParameters, char nestedTypeDelimiter)
{
public DisplayNameOptions(bool fullName, bool includeGenericParameterNames, bool includeGenericParameters, char nestedTypeDelimiter)
{
FullName = fullName;
IncludeGenericParameters = includeGenericParameters;
IncludeGenericParameterNames = includeGenericParameterNames;
NestedTypeDelimiter = nestedTypeDelimiter;
}

public bool FullName { get; }
public bool FullName { get; } = fullName;

public bool IncludeGenericParameters { get; }
public bool IncludeGenericParameters { get; } = includeGenericParameters;

public bool IncludeGenericParameterNames { get; }
public bool IncludeGenericParameterNames { get; } = includeGenericParameterNames;

public char NestedTypeDelimiter { get; }
public char NestedTypeDelimiter { get; } = nestedTypeDelimiter;
}
}
1 change: 1 addition & 0 deletions AspNetCore.Examples.OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Examples.OpenTel
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A98F4720-450D-4CA0-B137-932A7FFA1F1A}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
README.md = README.md
EndProjectSection
EndProject
Expand Down

0 comments on commit fb1a345

Please sign in to comment.