.net-core

Correct pattern to dispose of cancellation token source

℡╲_俬逩灬. 提交于 2021-01-02 12:14:02
问题 Consider a scenario where you have some asynchronous work to be done and you can run it in a fire and forget mode. This asynchronous work is able to listen for cancellation and so you pass it a cancellation token in order to being able to cancel it. At a given moment in time we can decide to request the cancellation of the ongoing activity, by using the cancellation token source object from which we have taken the cancellation token. Because cancellation token source implements IDisposable ,

Correct pattern to dispose of cancellation token source

◇◆丶佛笑我妖孽 提交于 2021-01-02 12:13:03
问题 Consider a scenario where you have some asynchronous work to be done and you can run it in a fire and forget mode. This asynchronous work is able to listen for cancellation and so you pass it a cancellation token in order to being able to cancel it. At a given moment in time we can decide to request the cancellation of the ongoing activity, by using the cancellation token source object from which we have taken the cancellation token. Because cancellation token source implements IDisposable ,

Correct pattern to dispose of cancellation token source

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-02 12:10:16
问题 Consider a scenario where you have some asynchronous work to be done and you can run it in a fire and forget mode. This asynchronous work is able to listen for cancellation and so you pass it a cancellation token in order to being able to cancel it. At a given moment in time we can decide to request the cancellation of the ongoing activity, by using the cancellation token source object from which we have taken the cancellation token. Because cancellation token source implements IDisposable ,

.NET Core 3.1 loading config from appsettings.json for console application

荒凉一梦 提交于 2021-01-02 06:15:42
问题 For .NET Core 3.1, console application how can I read a complex object from appsetting.json file and cast it into the corresponding object? All the examples I see online seem to be for previous versions of .NET core and things seems to have changed since then. Below is my sample code. I don't really know how to proceed from here. Thank you for your help. appsettings.json { "Player": { "Name": "Messi", "Age": "31", "Hobby": "Football" } } Player.cs class Player { public string Name { get; set;

.NET Core 3.1 loading config from appsettings.json for console application

淺唱寂寞╮ 提交于 2021-01-02 06:14:24
问题 For .NET Core 3.1, console application how can I read a complex object from appsetting.json file and cast it into the corresponding object? All the examples I see online seem to be for previous versions of .NET core and things seems to have changed since then. Below is my sample code. I don't really know how to proceed from here. Thank you for your help. appsettings.json { "Player": { "Name": "Messi", "Age": "31", "Hobby": "Football" } } Player.cs class Player { public string Name { get; set;

System.Text.Json.JsonSerializer.Serialize returns empty Json object “{}” [duplicate]

泄露秘密 提交于 2021-01-02 05:27:11
问题 This question already has answers here : How to use class fields with System.Text.Json.JsonSerializer? (2 answers) Closed 1 year ago . Environment: Visual Studio 2019 16.3.8, .NET 3.0.100, .NET Core 3.0 unit test. All 3 calls below to System.Text.Json.JsonSerializer.Serialize return empty objects: "{}" I must be doing something wrong ... but I just don't see it? public class MyObj { public int myInt; } [TestMethod] public void SerializeTest() { var myObj = new MyObj() { myInt = 99 }; var txt1

Obtaining file extended properties in .Net Core

人盡茶涼 提交于 2021-01-02 04:57:42
问题 I want to read extended properties like Product Version , Author , etc. from a file using .Net Core . There were classes like FileVersionInfo that used to provide version information, Shell object to read more about file, etc. Now, I don't find such classes any more. How do I read such info using .Net Core ? 回答1: FileVersionInfo can be easily found on NuGet, it's been located in System.Diagnostics namespace from the beginning, so you need just to install the package: Install-Package System

Obtaining file extended properties in .Net Core

最后都变了- 提交于 2021-01-02 04:56:06
问题 I want to read extended properties like Product Version , Author , etc. from a file using .Net Core . There were classes like FileVersionInfo that used to provide version information, Shell object to read more about file, etc. Now, I don't find such classes any more. How do I read such info using .Net Core ? 回答1: FileVersionInfo can be easily found on NuGet, it's been located in System.Diagnostics namespace from the beginning, so you need just to install the package: Install-Package System

QueryOption Search in Graph API for email address

守給你的承諾、 提交于 2021-01-01 13:51:14
问题 I would like to search in my sent folder for every email that is sent to "john.smith1@gmail.com" I tried the following List<QueryOption> queryOptions = new List<QueryOption> { new QueryOption("$search", "john.smith1@gmail.com") }; List<QueryOption> queryOptions = new List<QueryOption> { new QueryOption("$search", "john.smith1%40gmail.com") }; List<QueryOption> queryOptions = new List<QueryOption> { new QueryOption("$search", "to:john.smith1@gmail.com") }; List<QueryOption> queryOptions = new

Serilog - Separate files for Information, exception using appsetting.json

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-01 09:36:59
问题 I am writing all logs into one file(s) using rolling. But I want to separate them by Information , Warning and Exceptions rolling files. my current configuration is like this "Serilog": { "WriteTo": [ { "Name": "RollingFile", "Args": { "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", "pathFormat": "logs\\log-{Hour}.log", "rollOnFileSizeLimit ": true, "retainedFileCountLimit ": null, "rollingInterval": "Hour", "fileSizeLimitBytes": 5000000 }