Skip to content

Commit

Permalink
refactor: apply dotnet-format
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi committed Jan 3, 2024
1 parent 762c688 commit 10eb3df
Show file tree
Hide file tree
Showing 50 changed files with 180 additions and 175 deletions.
4 changes: 2 additions & 2 deletions samples/DotNetCoreSample/AppHostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
_listener.Start();
var logger = _serviceProvider.GetRequiredService<ILogger<HttpListenerWebServer>>();
logger.LogInformation("WebServer started");

while (!cancellationToken.IsCancellationRequested)
{
var listenerContext = await _listener.GetContextAsync();
Expand Down Expand Up @@ -135,7 +135,7 @@ public WebServerHostedService(IWebServer server)
{
_server = server;
}

public override async Task StopAsync(CancellationToken cancellationToken)
{
await _server.StopAsync(cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions samples/DotNetCoreSample/CommandExecutorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public static void MainTest()
ExecuteAndCapture("hostname")
.PrintOutputToConsole()
.EnsureSuccessExitCode();

ExecuteAndOutput("hostname").EnsureSuccessExitCode();

ExecuteAndOutputAsync("hostname").Wait();

ExecuteCommandAndOutput("hostname").EnsureSuccessExitCode();
}
}
10 changes: 5 additions & 5 deletions samples/DotNetCoreSample/DisposeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void MainTest()
Name = "MainTest2"
};
Console.WriteLine(service.GetType());

service = null;
Console.WriteLine(service is null);
}
Expand All @@ -39,7 +39,7 @@ public static void MainTest()

Console.WriteLine(@$"---- {nameof(MainTest)} end");
}

public static async ValueTask MainTestAsync()
{
Console.WriteLine(@$"---- {nameof(MainTestAsync)} start");
Expand All @@ -63,7 +63,7 @@ public static async ValueTask MainTestAsync()
Name = "MainTestAsync2"
};
Console.WriteLine(service.GetType());

service = null;
Console.WriteLine(service is null);
}
Expand All @@ -77,12 +77,12 @@ public static async ValueTask MainTestAsync()
file sealed class TestService : DisposableBase
{
public required string Name { get; init; }

protected override void Dispose(bool disposing)
{
if (disposing)
{
Console.WriteLine($@"<<{Name}>> disposes managed resources");
Console.WriteLine($@"<<{Name}>> disposes managed resources");
}
Console.WriteLine($@"<<{Name}>> disposes unmanaged resources");
base.Dispose(disposing);
Expand Down
10 changes: 5 additions & 5 deletions samples/DotNetCoreSample/NewtonJsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace DotNetCoreSample;

public sealed class NewtonJsonFormatterOptions: ConsoleFormatterOptions
public sealed class NewtonJsonFormatterOptions : ConsoleFormatterOptions
{
}

public sealed class NewtonJsonFormatter: ConsoleFormatter
public sealed class NewtonJsonFormatter : ConsoleFormatter
{
public const string FormatterName = "NewtonJson";

private readonly NewtonJsonFormatterOptions _options;

public NewtonJsonFormatter(IOptions<NewtonJsonFormatterOptions> options) : base(FormatterName)
Expand Down Expand Up @@ -73,7 +73,7 @@ public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeP
}
writer.WriteEndObject();
}

writer.WriteEndObject();
writer.Flush();
textWriter.WriteLine();
Expand All @@ -82,7 +82,7 @@ public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeP

public static partial class LoggingBuilderExtensions
{
public static ILoggingBuilder AddNewtonJsonConsole(this ILoggingBuilder loggingBuilder,
public static ILoggingBuilder AddNewtonJsonConsole(this ILoggingBuilder loggingBuilder,
Action<NewtonJsonFormatterOptions>? optionsConfigure = null)
{
loggingBuilder.AddConsole(options => options.FormatterName = NewtonJsonFormatter.FormatterName);
Expand Down
4 changes: 2 additions & 2 deletions samples/DotNetCoreSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Net.Mime;
// Copyright (c) Weihan Li. All rights reserved.
// Copyright (c) Weihan Li. All rights reserved.
// Licensed under the Apache license.

using DotNetCoreSample;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Mime;
using WeihanLi.Common;
using WeihanLi.Common.Aspect;
using WeihanLi.Common.Event;
Expand Down
2 changes: 1 addition & 1 deletion src/WeihanLi.Common/Aspect/AspectDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void InvokeInternal(IInvocation invocation, IReadOnlyList<IInterce
}
}
}

[RequiresUnreferencedCode("Unreferenced code may be used.")]
private static Func<IInvocation, Task> GetAspectDelegate(IInvocation invocation, IReadOnlyList<IInterceptor>? interceptors, Func<IInvocation, Task>? completeFunc)
{
Expand Down
14 changes: 7 additions & 7 deletions src/WeihanLi.Common/Aspect/FluentAspectOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static IInterceptionConfiguration InterceptMethod(this FluentAspectOption
return options.InterceptMethod(m => m.GetSignature().Equals(methodSignature));
}

public static IInterceptionConfiguration InterceptPropertyGetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(this FluentAspectOptions options,
public static IInterceptionConfiguration InterceptPropertyGetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(this FluentAspectOptions options,
Expression<Func<T, object>> expression)
{
var prop = expression.GetProperty();
Expand All @@ -84,7 +84,7 @@ public static IInterceptionConfiguration InterceptMethod(this FluentAspectOption
return options.InterceptMethod<T>(prop.GetMethod);
}

public static IInterceptionConfiguration InterceptPropertySetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(this FluentAspectOptions options,
public static IInterceptionConfiguration InterceptPropertySetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(this FluentAspectOptions options,
Expression<Func<T, object>> expression)
{
var prop = expression.GetProperty();
Expand Down Expand Up @@ -234,7 +234,7 @@ public static FluentAspectOptions NoInterceptMethod(this FluentAspectOptions opt
return options.NoInterceptMethod(m => m.GetSignature().Equals(methodSignature));
}

public static FluentAspectOptions NoInterceptProperty<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(this FluentAspectOptions options,
public static FluentAspectOptions NoInterceptProperty<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(this FluentAspectOptions options,
Expression<Func<T, object>> expression)
{
var prop = expression.GetProperty();
Expand All @@ -254,7 +254,7 @@ public static FluentAspectOptions NoInterceptMethod(this FluentAspectOptions opt
return options;
}

public static FluentAspectOptions NoInterceptPropertyGetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(this FluentAspectOptions options,
public static FluentAspectOptions NoInterceptPropertyGetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(this FluentAspectOptions options,
Expression<Func<T, object>> expression)
{
var prop = expression.GetProperty();
Expand All @@ -271,7 +271,7 @@ public static FluentAspectOptions NoInterceptMethod(this FluentAspectOptions opt
return options.NoInterceptMethod<T>(prop.GetMethod);
}

public static FluentAspectOptions NoInterceptPropertySetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(this FluentAspectOptions options,
public static FluentAspectOptions NoInterceptPropertySetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(this FluentAspectOptions options,
Expression<Func<T, object>> expression)
{
var prop = expression.GetProperty();
Expand Down Expand Up @@ -323,8 +323,8 @@ public static FluentAspectOptions UseProxyFactory<TProxyFactory>(this FluentAspe
options.ProxyFactory = new TProxyFactory();
return options;
}
public static FluentAspectOptions UseProxyFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TProxyFactory>(this FluentAspectOptions options,

public static FluentAspectOptions UseProxyFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProxyFactory>(this FluentAspectOptions options,
params object[] parameters) where TProxyFactory : class, IProxyFactory
{
options.ProxyFactory = ActivatorHelper.CreateInstance<TProxyFactory>(parameters);
Expand Down
2 changes: 1 addition & 1 deletion src/WeihanLi.Common/Aspect/IInterceptionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static IInterceptionConfiguration With(this IInterceptionConfiguration in
return interceptionConfiguration;
}

public static IInterceptionConfiguration With<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TInterceptor>(this IInterceptionConfiguration interceptionConfiguration, params object?[] parameters) where TInterceptor : IInterceptor
public static IInterceptionConfiguration With<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TInterceptor>(this IInterceptionConfiguration interceptionConfiguration, params object?[] parameters) where TInterceptor : IInterceptor
{
if (Guard.NotNull(parameters, nameof(parameters)).Length == 0)
{
Expand Down
10 changes: 5 additions & 5 deletions src/WeihanLi.Common/Aspect/ProxyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class ProxyUtils
"GetType",
"Finalize",
};

static ProxyUtils()
{
var asmBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(ProxyAssemblyName), AssemblyBuilderAccess.Run);
Expand Down Expand Up @@ -70,7 +70,7 @@ private static string GetFriendlyTypeName(this Type? type)

return type.IsBasicType() ? type.Name : type.FullName ?? type.Name;
}

[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
[RequiresUnreferencedCode("Unreferenced code may be used")]
public static Type CreateInterfaceProxy(Type interfaceType)
Expand Down Expand Up @@ -315,7 +315,7 @@ public static Type CreateInterfaceProxy(Type interfaceType, Type? implementType)
public static Type CreateClassProxy(Type serviceType, Type? implementType)
{
Guard.NotNull(serviceType);

if (implementType is null)
{
implementType = serviceType;
Expand Down Expand Up @@ -767,7 +767,7 @@ private static GenericParameterAttributes ToClassGenericParameterAttributes(Gene
return GenericParameterAttributes.None;
}
}

[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
[RequiresUnreferencedCode("Unreferenced code may be used")]
private static CustomAttributeBuilder DefineCustomAttribute(CustomAttributeData customAttributeData)
Expand All @@ -776,7 +776,7 @@ private static CustomAttributeBuilder DefineCustomAttribute(CustomAttributeData
if (customAttributeData.NamedArguments is null)
return new CustomAttributeBuilder(customAttributeData.Constructor,
customAttributeData.ConstructorArguments.Select(c => c.Value).ToArray());

var attributeTypeInfo = customAttributeData.AttributeType.GetTypeInfo();
var constructorArgs = customAttributeData.ConstructorArguments
.Select(ReadAttributeValue)
Expand Down
8 changes: 4 additions & 4 deletions src/WeihanLi.Common/CacheUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public static class CacheUtil
{
private static readonly ConcurrentDictionary<Type, PropertyInfo[]> TypePropertyCache = new();
private static readonly ConcurrentDictionary<Type, FieldInfo[]> TypeFieldCache = new();
public static PropertyInfo[] GetTypeProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]Type type)

public static PropertyInfo[] GetTypeProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
{
Guard.NotNull(type);
return TypePropertyCache.GetOrAdd(type, _ => type.GetProperties());
}
public static FieldInfo[] GetTypeFields([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]Type type)

public static FieldInfo[] GetTypeFields([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type type)
{
Guard.NotNull(type);
return TypeFieldCache.GetOrAdd(type, _ => type.GetFields());
Expand Down
2 changes: 1 addition & 1 deletion src/WeihanLi.Common/Data/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace WeihanLi.Common.Data;

[CLSCompliant(false)]
public class Repository<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.PublicProperties)]TEntity> : IRepository<TEntity> where TEntity : new()
public class Repository<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] TEntity> : IRepository<TEntity> where TEntity : new()
{
#region TODO: Cache External

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void Dispose()
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
private object? GetServiceInstance(Type serviceType, ServiceDefinition serviceDefinition)
=> EnrichObject(GetServiceInstanceInternal(serviceType, serviceDefinition));

[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
private object? GetServiceInstanceInternal(Type serviceType, ServiceDefinition serviceDefinition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace WeihanLi.Common.DependencyInjection;

public static partial class ServiceContainerBuilderExtensions
{
public static IServiceContainerBuilder AddSingleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TService>(this IServiceContainerBuilder serviceContainerBuilder, TService service)
public static IServiceContainerBuilder AddSingleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(this IServiceContainerBuilder serviceContainerBuilder, TService service)
{
Guard.NotNull(service, nameof(service));
serviceContainerBuilder.Add(new ServiceDefinition(service!, typeof(TService)));
Expand Down Expand Up @@ -182,7 +182,7 @@ public static IServiceContainerBuilder RegisterAssemblyTypesAsImplementedInterfa
/// <param name="serviceLifetime">service lifetime</param>
/// <returns>services</returns>
public static IServiceContainerBuilder RegisterTypeAsImplementedInterfaces(
this IServiceContainerBuilder services, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]Type type,
this IServiceContainerBuilder services, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type,
ServiceLifetime serviceLifetime = ServiceLifetime.Singleton)
=> RegisterTypeAsImplementedInterfaces(services, type, null, serviceLifetime);

Expand All @@ -194,7 +194,7 @@ public static IServiceContainerBuilder RegisterTypeAsImplementedInterfaces(
/// <param name="interfaceTypeFilter">interfaceTypeFilter</param>
/// <param name="serviceLifetime">service lifetime</param>
/// <returns>services</returns>
public static IServiceContainerBuilder RegisterTypeAsImplementedInterfaces(this IServiceContainerBuilder services, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]Type type, Func<Type, bool>? interfaceTypeFilter, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton)
public static IServiceContainerBuilder RegisterTypeAsImplementedInterfaces(this IServiceContainerBuilder services, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, Func<Type, bool>? interfaceTypeFilter, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton)
{
Guard.NotNull(type);
foreach (var interfaceType in type.GetImplementedInterfaces())
Expand Down
14 changes: 7 additions & 7 deletions src/WeihanLi.Common/DependencyInjection/ServiceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ public static ServiceDefinition Singleton<TService>(Func<IServiceProvider, objec
return new(typeof(TService), factory, ServiceLifetime.Singleton);
}

public static ServiceDefinition Singleton<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TServiceImplement>() where TServiceImplement : TService
public static ServiceDefinition Singleton<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TServiceImplement>() where TServiceImplement : TService
{
return new(typeof(TService), typeof(TServiceImplement), ServiceLifetime.Singleton);
}

public static ServiceDefinition Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TService>()
public static ServiceDefinition Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>()
{
return new(typeof(TService), ServiceLifetime.Singleton);
}

public static ServiceDefinition Scoped<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TService>(Func<IServiceProvider, object> factory)
public static ServiceDefinition Scoped<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(Func<IServiceProvider, object> factory)
{
return new(typeof(TService), factory, ServiceLifetime.Scoped);
}

public static ServiceDefinition Scoped<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TServiceImplement>() where TServiceImplement : TService
public static ServiceDefinition Scoped<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TServiceImplement>() where TServiceImplement : TService
{
return new(typeof(TService), typeof(TServiceImplement), ServiceLifetime.Scoped);
}

public static ServiceDefinition Scoped<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TService>()
public static ServiceDefinition Scoped<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>()
{
return new(typeof(TService), ServiceLifetime.Scoped);
}
Expand All @@ -88,12 +88,12 @@ public static ServiceDefinition Transient<TService>(Func<IServiceProvider, objec
return new(typeof(TService), factory, ServiceLifetime.Transient);
}

public static ServiceDefinition Transient<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TService>()
public static ServiceDefinition Transient<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>()
{
return new(typeof(TService), ServiceLifetime.Transient);
}

public static ServiceDefinition Transient<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TServiceImplement>() where TServiceImplement : TService
public static ServiceDefinition Transient<TService, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TServiceImplement>() where TServiceImplement : TService
{
return new(typeof(TService), typeof(TServiceImplement), ServiceLifetime.Transient);
}
Expand Down
Loading

0 comments on commit 10eb3df

Please sign in to comment.