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
using System; | |
public class C { | |
public void M(string value) | |
{ | |
if (value is null!) throw new ArgumentNullException(nameof(value)); | |
// works in NET 5 (C#9) but fails in 6 RC1 (C#10) with error CS8598: The suppression operator is not allowed in this context | |
// I can see why as the null does not need a null foriving as string is not a declared string? | |
// so it is correct to flag as a code smell, but should the error CS8598 be an error or a warning when migrating NET5 code? |
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
private interface IKelvinMapper | |
{ | |
decimal ToKelvins(decimal value); | |
} | |
private class CentigradeToKelvinMapper : IKelvinMapper | |
{ | |
public decimal ToKelvins(decimal value) => value + 273.15M; | |
} |
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
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
public void ConfigureServices(IServiceCollection services) |
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
public interface IAppSettings | |
{ | |
string ApplicationName { get; } | |
} | |
public interface ISqlConnectionSettings | |
{ | |
string SqlConnectionSting { 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
public class MyAppSettingsBridge : IAppSettingsResolved | |
{ | |
private readonly IOptions<MyAppSettings> _appSettings; | |
private readonly ISettingsDecrypt _decryptor; | |
public MyAppSettingsBridge(IOptionsSnapshot<MyAppSettings> appSettings, ISettingsDecrypt decryptor, ISettingsValidator validator) { | |
_appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings)); | |
_decryptor = decryptor ?? throw new ArgumentException(nameof(decryptor)); | |
if (validator == null) throw new ArgumentNullException(nameof(validator)); |
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
public class SettingsValidator : ISettingsValidator | |
{ | |
public bool TryValidate(IAppSettingsStructure settings, out AggregateException validationExceptions) | |
{ | |
if (settings == null) throw new ArgumentNullException(nameof(settings)); | |
var exceptions = new List<Exception>(); | |
if (settings.ApplicationName == null) exceptions.Add(new ArgumentNullException(nameof(settings.ApplicationName))); | |
if (string.IsNullOrWhiteSpace(settings.ApplicationName)) exceptions.Add(new ArgumentOutOfRangeException(nameof(settings.ApplicationName))); |
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
public class SettingsDecryptor : ISettingsDecrypt | |
{ | |
private readonly ICryptoAlgorithm _crypto; | |
public SettingsDecryptor(ICryptoAlgorithm crypto) | |
{ | |
_crypto = crypto ?? throw new ArgumentNullException(nameof(crypto)); | |
} | |
public string Decrypt(string key, IDictionary<string, string> keyValues) | |
{ |
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
public interface ICryptoFactory | |
{ | |
ICryptoAlgorithm Create<T>(string password, string salt) where T : SymmetricAlgorithm, new(); | |
ICryptoAlgorithm Create(Type type, string password, string salt); | |
} | |
public interface ICryptoAlgorithm | |
{ | |
string Decrypt(string text); | |
string Encrypt(string text); |
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
public class MyAppSettings : IAppSettingsStructure | |
{ | |
public string ApplicationName { get; set; } | |
public Dictionary<string, string> Secrets { get; set; } = new Dictionary<string, string>(); | |
} |
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
{ | |
"Logging": { | |
"IncludeScopes": false, | |
"LogLevel": { | |
"Default": "Warning" | |
} | |
}, | |
"MyAppSettings": { | |
"ApplicationName": "My Cool Application", | |
"Secrets": { |
NewerOlder