Convert IEnumeable collection of anonymous type into typed List

Here is the creation of anonymous type IEnumeable collection: Class SimpleType { public int Id { get; set; } } List<SimpleType> myCollection = new List<SimpleType>(); // Populating myCollection omitted // .... // Get IEnumeable collection of anonymous type var anonymous = from t in myCollection group t by new { t.Id } into gt where … Continue reading Convert IEnumeable collection of anonymous type into typed List

Net Core – read int or string array from appsettings.json

Row on appsettings.json: "SectionName": { "intArray": [ 1, 2, 3, 4 ], "stringArray": [ "a", "b"] } Net Core web application private readonly IConfiguration _configuration; Into your function: List<int> intArray= _configuration.GetSection("SectionName:intArray").Get(int[]).ToList(); List<string> stringArray= _configuration.GetSection("SectionName:stringArray").Get(string[]).ToList(); Console application var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.SetBasePath(System.IO.Directory.GetCurrentDirectory()); configurationBuilder.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true); var configuration = configurationBuilder.Build(); List<int> intArray= configuration.GetSection("SectionName:intArray").Get(int[]).ToList(); … Continue reading Net Core – read int or string array from appsettings.json

Detecting Debug mode on Net Core

To detect if the Assembly is on Debug mode: Using reflection bool debugMode = false; // Detect debug mode if (attribs.Length > 0) { var debuggableAttribute = attribs[0] as DebuggableAttribute; if (debuggableAttribute != null) { debugMode = debuggableAttribute.IsJITOptimizerDisabled ? true : false; } } Using csproj constants Another solution is to use DEBUG constants, so … Continue reading Detecting Debug mode on Net Core