public void When_ReferenceTypeNullHandling_is_NotNull_then_nullability_is_correct() { //// Arrange var checks = new Dictionary <Type, bool> { { typeof(bool), false }, { typeof(int), false }, { typeof(char), false }, { typeof(short), false }, { typeof(long), false }, { typeof(DateTime), false }, { typeof(NodaTime.Instant), false }, { typeof(long?), true }, { typeof(string), false }, { typeof(Uri), false }, { typeof(object), false }, { typeof(JsonSchemaGeneratorSettings), false }, { typeof(IReflectionService), false }, { typeof(Type), false }, { typeof(byte[]), false }, { typeof(NodaTime.DateTimeZone), false }, { typeof(Dictionary <string, string>), false }, }; //// Act var svc = new DefaultReflectionService(); //// Assert foreach (var check in checks) { Assert.Equal(check.Value, svc.IsNullable(check.Key, null, ReferenceTypeNullHandling.NotNull)); } }
public virtual async Task FindAndProcessConfigurationHooks(TConfiguration configuration) { if (configuration == null) { return; } var diagnosticService = configuration.DiagnosticService; var reflectionService = new DefaultReflectionService(diagnosticService); var hookTypes = reflectionService.FindConcreteSubtypes <IConfigurationHook>(); foreach (var hookType in hookTypes.Distinct()) { try { await diagnosticService.EmitAsync( new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationHook) { Detail = "Found configuration hook " + hookType, }.Build()); var hook = (IConfigurationHook)Activator.CreateInstance(hookType); hook.Configure(configuration); await diagnosticService.EmitAsync( new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationHook) { Detail = "Configuration hook " + hookType + " processed successfully" }.Build()); } catch (Exception ex) { diagnosticService.Emit(new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationError) { Detail = "Unhandled exception processing configuration hook " + hookType, Exception = ex }.Build()); } } var asyncHookTypes = reflectionService.FindConcreteSubtypes <IAsyncConfigurationHook>(); foreach (var hookType in asyncHookTypes.Distinct()) { try { await diagnosticService.EmitAsync(new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationHook) { Detail = "Found async configuration hook " + hookType, }.Build()); var hook = (IAsyncConfigurationHook)Activator.CreateInstance(hookType); await hook.Configure(configuration); await diagnosticService.EmitAsync(new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationHook) { Detail = "Async configuration hook " + hookType + " processed successfully" }.Build()); } catch (Exception ex) { diagnosticService.Emit(new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationError) { Detail = "Unhandled exception processing async configuration hook " + hookType, Exception = ex }.Build()); } } }