https://software.codidact.com/categories/38/tags/3298.rssNew Posts Tagged 'c#' - Software DevelopmentSoftware Development - Codidact2024-01-10T21:16:12Zhttps://software.codidact.com/posts/290534Does Socket.AcceptAsync throw SocketException for any transient reason?Kevin Krumwiedehttps://software.codidact.com/users/659442024-01-09T17:02:50Z2024-01-10T21:16:12Z<p>I'm writing exception handling around a call to <a href="https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.acceptasync?view=net-8.0#system-net-sockets-socket-acceptasync(sys...https://software.codidact.com/posts/290274How to programmatically evaluate Excel data validations using .NET?torarittehttps://software.codidact.com/users/658732023-11-23T03:30:28Z2023-11-24T12:45:00Z<p>What I would like to do:</p>
<ol>
<li>Set a cell value.</li>
<li>Check with a program if cell values conform to data validation rules.</li>
</ol>
<p>I could extract all the information need...https://software.codidact.com/posts/290255Which .NET project can programmatically validate a cell's value out of the box based on Excel data validation constraints?torarittehttps://software.codidact.com/users/658732023-11-20T20:09:50Z2023-11-23T03:27:52Z<p>Are any of the popular Excel .NET projects have a functionality similar to Apache POI's <a href="https://poi.apache.org/apidocs/dev/org/apache/poi/ss/formula/DataValidationEvaluator.html"><code>...https://software.codidact.com/posts/289844Is it possible to re-export types similar to JS?raphaelschmitzhttps://software.codidact.com/users/532822023-09-29T17:40:13Z2023-11-12T09:51:22Z<p>I'm writing a library "MyLibrary".</p>
<p>In there, I group code into sections that make sense.<br>
Let's say I have a folder "Reports" and a folder "Helpers".</p>
<p>I would like to have my ...https://software.codidact.com/posts/290173Winui 3 Combobox in datagrid not displaying dataFrankLukehttps://software.codidact.com/users/81352023-11-05T20:44:34Z2023-11-05T20:44:34Z<p>I am migrating a WPF app to WinUI3. Things went well until I needed to put a combo box in the datagrid. That MS had removed the datagrid from the standard tools was overcome with <a href="https:...https://software.codidact.com/posts/282544Find the name of the student with the top mark, display their name and markInPuthttps://software.codidact.com/users/541602021-07-05T14:20:50Z2023-10-25T23:42:21Z<p>I have a CSV file like this:</p>
<pre><code>name,surname,score
Moon,Walko,148
Jerald,Gryder,150
</code></pre>
<p>I need to find the highest score. My attempt:</p>
<pre><code class="languag...https://software.codidact.com/posts/288407How can I return XML from BeforeSendRequest and AfterReceiveReply to the calling method in a thread-safe way?Celarixhttps://software.codidact.com/users/624582023-06-13T23:55:30Z2023-06-22T16:35:15Z<p>We have a console application using the Azure WebJob SDK. The WebJob relies on a WCF service using SOAP, which it accesses through a DLL we wrote that wraps the auto-generated WCF types in somet...https://software.codidact.com/posts/287602When would one not want to return an interface?Moshihttps://software.codidact.com/users/531962022-12-21T22:49:47Z2023-06-16T22:10:50Z<p>Consider the following method as an example:</p>
<pre><code class="language-cs">List<int> Foo() {
// ...
}
</code></pre>
<p>Are there any disadvantages of returning an interface i...https://software.codidact.com/posts/288121Library that is platform-specific via selective compilation?plodhttps://software.codidact.com/users/604492023-05-12T09:27:56Z2023-06-02T12:44:47Z<p>The proposed library would sit alongside cross-platform libraries in Xamarin apps for iOS and Android. However, it would include files with names like</p>
<pre><code>MyLibraryFile.android.cs
...https://software.codidact.com/posts/287994Updating the database reverses previous changesMoshihttps://software.codidact.com/users/531962023-03-27T01:41:27Z2023-04-29T10:44:29Z<h2>The Code</h2>
<pre><code class="language-cs">using Microsoft.EntityFrameworkCore;
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public D...https://software.codidact.com/posts/287298Datagrid in MVVM saves edits but not insertsFrankLukehttps://software.codidact.com/users/81352022-10-23T00:26:57Z2022-10-23T08:36:11Z<p>I am writing a todolist application in WPF with MVVM. I display the goals in a datagrid and the editing works fine. Changes made in the grid are saved to the DB when I click save. However, addin...https://software.codidact.com/posts/287287How to define Polly policies when working with Refit library in ASP.NET Core?Alexeihttps://software.codidact.com/users/531772022-10-20T10:49:40Z2022-10-20T10:53:42Z<p>Note: this is based on my question on SO and subsequent activity <a href="https://stackoverflow.com/q/74055782/2780791">there</a></p>
<p>I am trying to add resilience using <a href="https://git...https://software.codidact.com/posts/287235How to refer to the same class twice from one Entity Framework entity?FrankLukehttps://software.codidact.com/users/81352022-10-11T21:03:15Z2022-10-12T18:03:35Z<p>I have two classes, Contestant and Picture, with the following setup:</p>
<pre><code>public class Contestant
{
...
public int AvatarID { get; set; }
[ForeignKey(nameof(Avatar...https://software.codidact.com/posts/287069How to generate random objects at different locations on x, y, z axissimonJNhttps://software.codidact.com/users/570012022-09-25T06:58:27Z2022-10-05T09:36:55Z<p>I have been trying to generate a random object on all three axis in different locations. However, Vector3 doesn't accept that many overloads e.g:</p>
<p><code>Vector3 spawnPos = new Vector3(Ran...https://software.codidact.com/posts/286715Working with a generic class that uses a type that should be of generic typeAlexeihttps://software.codidact.com/users/531772022-07-13T08:12:21Z2022-07-13T08:12:21Z<p>I have followed <a href="https://www.youtube.com/watch?v=a1ye9eGTB98">Nick Chapsas' tutorial </a> to avoid throwing a ValidationException to treat validation errors and instead rely on <code>Lan...https://software.codidact.com/posts/286520C# WPF datagrid not persisting insertsFrankLukehttps://software.codidact.com/users/81352022-05-28T22:30:03Z2022-05-28T22:30:03Z<p>I am working with VS 2022 and trying to make a WPF MVVM application. The application updates the items displayed in the datagrid, persisting the changes to the database upon save. However, addin...https://software.codidact.com/posts/286164WPF MVVM ListBox not updatingFrankLukehttps://software.codidact.com/users/81352022-03-27T19:44:44Z2022-03-29T09:29:16Z<p>I am trying to combine MVVM in WPF using Microsoft.Toolkit.MVVM. Somethings are working as expected. The text boxes bind to fields and update in both directions. The button command executes and ...https://software.codidact.com/posts/285839Measuring arithmetic overflow checking overhead in C#Alexeihttps://software.codidact.com/users/531772022-02-05T16:04:35Z2022-02-12T23:48:48Z<p><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/checked">Overflow checking for integral-type arithmetic operations</a> is <a href="https://docs.microsoft.com/...https://software.codidact.com/posts/285873What are the drawbacks of using data snapshot testing?Alexeihttps://software.codidact.com/users/531772022-02-08T16:35:27Z2022-02-09T10:21:01Z<p>Our team is finally focusing on writing more automatic testing and one of my ex-colleagues recommended to try out the <a href="https://github.com/VerifyTests/Verify">Verify library</a>.</p>
<p>...https://software.codidact.com/posts/285836Why static code analyzers such as SonarQube indicate a high code complexity for switch statements?Alexeihttps://software.codidact.com/users/531772022-02-05T15:38:05Z2022-02-07T01:18:42Z<p>During a presentation of a pipeline configuration, a colleague showed a SonarQube integration and one of its reports. A warning was caused by overrunning the max value for the code complexity th...https://software.codidact.com/posts/285438How to dynamically change panel of ItemsControl?FoggyFinderhttps://software.codidact.com/users/532072021-12-31T17:07:54Z2022-01-01T10:00:55Z<p>Let's say I have some collection of data. My goal is to provide different kind of view of <code>ItemsControl</code> depending on user`s preference.</p>
<p>For simplicity, we can assume that use...https://software.codidact.com/posts/284345Get the length of a slice from a multi-dimensional arrayFrankLukehttps://software.codidact.com/users/81352021-09-25T21:27:41Z2021-09-26T08:32:38Z<p>If I have a one-dimensional array, I can get the length of it quite easily:
<code>var x = moves.Length()</code>.</p>
<p>However, if the array is multi-dimensional, <code>.Length()</code> retur...https://software.codidact.com/posts/284086Credentials for multiple tenants with Azure.IdentityPeter Taylorhttps://software.codidact.com/users/363562021-09-09T09:26:41Z2021-09-09T09:26:41Z<p>Situation: I have an Azure account which has management permissions for various subscriptions in various directories (tenants). I have a GUI tool to do various management tasks whose details are...https://software.codidact.com/posts/283247How do I redact values when Save()ing a yaml structure with YamlDotNet?ajvhttps://software.codidact.com/users/532422021-08-09T17:53:53Z2021-08-11T04:41:32Z<p>I handle several projects that use yaml files for configuration, and load them with <a href="https://github.com/aaubry/YamlDotNet">YamlDotNet</a>. It is sometimes useful to log the effective con...https://software.codidact.com/posts/282465Saving modified data in gridview on clicking SaveButtonCrihttps://software.codidact.com/users/541442021-06-30T07:54:14Z2021-06-30T18:54:14Z<p>I am struggling to do a save button in C# Windows Form Application where I have a GridView and I want to save all modifications I do in GridView Table(I connected it to SQL). This is the data so...https://software.codidact.com/posts/281853How to generate multi-line completions (code generation) with OpenAI?Alexeihttps://software.codidact.com/users/531772021-05-22T19:21:10Z2021-06-06T19:44:45Z<p>I have finally received access to a trial account on OpenAI and I took it for a spin. My interest is with code generation, so first tried something simple using the playground:</p>
<pre><code>Q...https://software.codidact.com/posts/281730Why are my EMA values different from the ones on the website?kolaahttps://software.codidact.com/users/539732021-05-13T16:52:30Z2021-05-14T06:14:10Z<p>I wrote a program for calculating EMA, but my values differ from the values calculated <a href="https://www.tradingview.com/utm_source=https://www.binance.com&utm_medium=library&utm_...https://software.codidact.com/posts/280920Update list based on presence of identifier in a second listFrankLukehttps://software.codidact.com/users/81352021-02-25T21:27:24Z2021-03-09T23:08:22Z<p>In C#, I have two lists and need to mark records in the first based on the second. Here's a sample:</p>
<pre><code>public class Vehicle
{
public string Make { get; set; }
public stri...https://software.codidact.com/posts/280755F-bounded polymorphism, interface operators, and type inference in C#Peter Taylorhttps://software.codidact.com/users/363562021-02-10T10:24:50Z2021-02-10T10:24:50Z<p>C# language version 8.0 introduces limited support for static methods, operators, etc. in interfaces. However, there are still limitations. I was hoping to use the new language features to try a...https://software.codidact.com/posts/280665Declaring interface members with generic return types: "The type parameter [generic type] cannot be used with type arguments"Marc.2377https://software.codidact.com/users/80642021-02-04T07:22:14Z2021-02-05T00:14:24Z<p>I'm trying to write an interface to define the set of operations I expect my repositories' Unit of Work implementations to have, and I want this interface to be fulfilled by EF Core's <code>DbCo...https://software.codidact.com/posts/280642C# WPF MVVM View & Get new record valuesgzi98https://software.codidact.com/users/537472021-02-01T15:45:56Z2021-02-02T14:46:42Z<p>Just looking to hear some reviews on my current MVVM Implementation, If I am heading towards the right direction. :)</p>
<p><strong>Code</strong></p>
<p><strong>BaseViewModel</strong></p>
<pr...https://software.codidact.com/posts/280599How to filter data from the view using MVVM Pattern?gzi98https://software.codidact.com/users/537472021-01-29T13:39:11Z2021-01-29T17:17:08Z<p>I am trying to filter data in the DataGrid using the texboxes using the MVVM pattern. Just not sure how to do it. Would appreciate any guidance.</p>
<p>My current code:</p>
<p><strong>Model</s...https://software.codidact.com/posts/280518C# MVVM Login Projectgzi98https://software.codidact.com/users/537472021-01-19T21:42:32Z2021-01-20T16:02:16Z<p>I was wondering if somebody can review my code? I am creating a simple login desktop application, just to get used to the MVVM pattern using WPF.</p>
<p><strong>View</strong></p>
<pre><code>&l...https://software.codidact.com/posts/278044Which abstraction should I choose for background services and why?Kir_Antipovhttps://software.codidact.com/users/534092020-09-12T19:46:03Z2020-10-27T08:53:28Z<p>Which concept is best for managed background services?</p>
<h3>1. <code>RunAsync(CancellationToken)</code>:</h3>
<pre><code class="language-csharp">interface IWorker
{
Task RunAsync(Cancella...https://software.codidact.com/posts/278694Cache data using Redis Cache in an ASP.NET Core 3.1 projectAlexeihttps://software.codidact.com/users/531772020-10-21T12:21:02Z2020-10-21T12:21:02Z<p><em>This is an <a href="https://codereview.stackexchange.com/questions/234060/cache-most-expensive-data-using-redis-cache-in-an-asp-net-core-project">unanswered code review request of mine</a> f...https://software.codidact.com/posts/278693Measure ASP.NET Core 3.1 Web API action execution timesAlexeihttps://software.codidact.com/users/531772020-10-21T12:15:41Z2020-10-21T12:15:41Z<p>This is basically <a href="https://codereview.stackexchange.com/questions/235812/accurately-measure-asp-net-core-3-x-actions-execution-times-web-api-project">an unanswered code review request</a...https://software.codidact.com/posts/278082How to perform LINQ joins with multiple fields in a single join?Alexeihttps://software.codidact.com/users/531772020-09-15T15:24:33Z2020-09-15T15:28:27Z<p><strong>Note:</strong> this is an aggregate of the answer provided for <a href="https://stackoverflow.com/questions/373541/how-to-do-joins-in-linq-on-multiple-fields-in-single-join/34176502#3417...https://software.codidact.com/posts/277946Is it recommended for ASP.NET Web API actions to always include a CancellationToken?Alexeihttps://software.codidact.com/users/531772020-09-06T13:43:06Z2020-09-10T11:22:41Z<p>Note: This is basically <a href="https://stackoverflow.com/questions/50329618/should-i-always-add-cancellationtoken-to-my-controller-actions?noredirect=1#comment112742019_50329618">a question</a...