Questions tagged [c#]
C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform
22 questions from the last 365 days
4
votes
1
answer
111
views
Async-ifying WPF Window.Show()?
I'm working on a WPF application which has many user interactions which start with opening a non model window, allowing some interaction with the window and the rest of the application (think ...
2
votes
2
answers
308
views
How should multiple ViewModels communicate in a larger WPF MVVM application?
I’m working on a WPF MVVM application that has grown beyond just one or two User Controls. I now have multiple ViewModels that need to react to each other’s actions (e.g., selecting a customer in one ...
8
votes
4
answers
2k
views
Entity Framework - Is there a safety mechanism to prevent accidentally running Update-Database?
When using Entity Framework and running the Update-Database command, non-updated applications that rely on the database crash due to database context changes.
Usually teams have a production database ...
4
votes
1
answer
1k
views
CA-1822: Mark members as static Roslyn recommendation will not unnecessarily increase memory consumption?
My job uses SonarQube as part of the CI/CD quality gate. One of the "Maintainability" issues (severity: medium) raised is the CA-1822: Mark members as static.
The link explains the added ...
1
vote
3
answers
245
views
Should HTTP clients be encapsulated in a C#/.NET library?
I have a C# library that contains all the logic to send requests to a remote endpoint, including marshalling/unmarshalling and encrypting/decrypting requests and responses. It contains an HttpClient ...
0
votes
2
answers
150
views
What are the trade-offs of recursively invoking an extension method as extension vs static?
When using recursion in an extension method, there are two different ways to invoke the method from within itself.
Option 1: As an extension method
internal static class MyExtension
{
public ...
16
votes
10
answers
5k
views
C#'s Aversion to Array
I have noticed in documentation, looking at open-source code bases, and just a general sense in the industry that C# developers largely prefer to use List<> or IEnumerable<> over simple ...
2
votes
3
answers
171
views
Should a web framework / template like Admin-LTE be put in source control alongside our own code?
My team does predominantly back-end work in C#, with a smattering of front-end web development using Angular. We're starting a new website project, based on the Admin LTE framework / template. This is ...
0
votes
2
answers
346
views
C# - Entity handler correct use clean code
I have a question about setting up my service. My main concern is if the design is clean and in order. Whether it meets the SOLID principles and does not spill out on me.
I have entities like order ...
3
votes
1
answer
164
views
Approaches to Razor without combining C# in HTML
The move to MVC and MVVM has not been easy for me. Combining multiple languages in single pages with inline code is something I find disorienting. I'd like to remedy this by attempting to use Razor ...
2
votes
1
answer
180
views
Should I split endpoints by parameter requirements?
Preface: This will not be available publicly or to third parties, so I am not concerned about users having the background knowledge to properly form GET requests. These are also not only analytical ...
1
vote
1
answer
321
views
Is there a better way to soft delete navigation properties in Entity Framework 6 when using Repository pattern?
public void ReassignLineItems(InvoiceUpdateDto invoiceUpdate)
{
Invoice invoiceInRepository = _unitOfWork.InvoiceRepository
.FirstOrDefault(invoice => invoice.Id == invoiceUpdate.Id);
...
2
votes
1
answer
145
views
Using partials to automate form inputs creation
My main focus is having as little duplicate code/files as possible.
Most of the HTML I write is almost identical.
There is already a form template which holds the form and several necessities. That ...
1
vote
1
answer
176
views
ASP.NET MVC and Web API Together vs. ASP.NET MVC with JSON-Returning Action Methods
In an ASP.NET MVC application with views that make AJAX calls for widgets like dropdowns and data grids, is it better to use Web API controllers or regular MVC action methods that return JSON?
The ...
0
votes
2
answers
239
views
Testing C# app backed by MSSQL database and Entity Framework - seeking advices for going with "test double" approach
I am new to C#, and Windows (coming from Python, Linux background). I need to add tests
to an existing C# codebase, which relies on a MSSQL database and Entity Framework.
In my old days when testing ...
1
vote
3
answers
519
views
C# var vs. interface vs. concrete class in object instantiation
As we know, there are (at least) four ways to instantiate a class object in C#. But I've never quite understood why some ways are better than others.
First of all, you can explicitly declare the ...
1
vote
3
answers
190
views
Are there non-inheritance-chain-mess ways to make modular libraries that rely on Entity Framework based on one DB context in the using project?
I am developing some modular libraries that contain common APIs, data, and functionality. One of the core assumptions to these libraries is you would use which you want to compose your project, but ...
4
votes
4
answers
474
views
Primary constructors for depedency injection
Microsoft identifies dependency injection as one of the uses for primary constructors.
public class ExampleController(IService service) : ControllerBase
{
[HttpGet]
public ActionResult<...
0
votes
4
answers
282
views
Use-cases for Expression<TDelegate> except translating to another language?
So I just learned about Expression<TDelegate>. As a library author this really intrigued me; my libraries make extensive use of source generators to generate both high-performance code and code ...
1
vote
1
answer
179
views
NUnit testOf attribute usage
What are the use cases of TestOf? I'm new to NUnit testing and from what I have seen, most people don't use this attribute that much.
From my experience, TestOf helped me to quickly identify what ...
17
votes
5
answers
3k
views
Should parameter names describe their object type?
I'm unsure whether parameter names should describe their object types or if shorter, more concise names are preferable.
Consider the following two method signatures:
public void PrintPoint(...
3
votes
3
answers
979
views
Testing for non-existence of a method in API
I am designing a fluent builder pattern API that branches and allows different options based on what has already been called.
For example: Build().Foo().Bar() is valid code, but Build().Baz().Bar() ...