Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c#]

C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

0
votes
0answers
15 views

Hints about analyzing single (huge) C# class using SonarQube and related issues

I'm doing an internship into a small company which is working on part of a systems which runs on a base already written by another company (many company are working on the same project) which is ...
2
votes
3answers
91 views

Is there a programming term that means property or field?

I think this question can span multiple languages, but in C# specifically there is a clear distinction between a field (ex: private int a;) and a property (ex: private int b { get; set; }). While ...
-2
votes
0answers
30 views

Return type of generic interface from method argument [on hold]

I have an generic interface IHaveChannels<T> with a method T GetChannelValue(int channelNumber). Also I have two classes implementing this interface. The first one as IHaveChannels<int>, ...
0
votes
0answers
16 views

What should be the code architecture to download and cache offline data (Images/Videos/3d Models)?

I'm developing an application which has a 3D room. Each room is a 3d model and can contain media boards. each media board contains image(s) as slides or video. I have created following Data Models : ...
2
votes
3answers
360 views

What is a good place, in OO, to store a string that is used many places?

I have a string that is used in a few places. string portalLoginPath = $"{Request.Scheme}{Uri.SchemeDelimiter}{Request.Host}/Account/Login"; I was thinking of creating a static class with a string ...
4
votes
2answers
559 views

Clean Code: Another question about boolean as function parameters [duplicate]

I had a discussion, if the code for calling information from a database can have a switch to show also deleted entries. Simplyfied the code (C#) look like this: void searchEntry(string searchValue, ...
-2
votes
0answers
21 views

Is it good idea to embed short-lived access token (bearor token) in HTTP header and pass it over url as qr-code string for login?

I have thought back of my mind to embed short-lived access token in HTTP header and pass it over url so that everytime when a mobile user scans the ID card (having url encoded string for example http:/...
1
vote
2answers
94 views

Loose project coupling causes problems in .NET Core solution

we started a new project in which back end consists of several layers (each in different project). For simplifaction I'll define a few: Project.Data -data layer with access to db Project.Repository -...
2
votes
4answers
101 views

Is Implementation class exposure fine in Dependency Inversion

Basically we should depend on abstractions instead of concrete classes, that's the Dependency Inversion main principle. interface ITest { void DoSomething(); } class TestImpl : ITest { ...
0
votes
1answer
51 views

Load files depending on browser or write workarounds within the file?

I'm writing up this website running under IIS with .NET Core. I developed most of the site with minimal use of JS so that the server will be doing most of the work (and thankfully so because of the ...
0
votes
3answers
136 views

Business logic contained inside JSON

I have recently looked at some Web APIs provided by well known companies' e.g. this one by HSBC: https://developer.hsbc.com/swagger-index.html#!/Products_Commercial_Credit_Cards/...
0
votes
1answer
79 views

Private class in ORM Repository?

Is this a code smell? I have a repository which connects to a SQL server. This repository uses Dapper to map the results to an object. I have a method in this repository that checks a result, then ...
9
votes
3answers
352 views

Do i still need to use fixed point to guarantee computers get the same result for math operations anymore?

I was told most modern computers follow the same floating point standard, does this mean they will all get the same float answer for a given math operation if the inputs are the same? I ask because i ...
2
votes
0answers
30 views

Is it safe to add extra role claims to the asp.net identity?

I am using the Azure AD authentication provider for the asp.net web application and I wish to add extra role claims (based on custom application logic, those cannot be provided from Azure AD). ...
-1
votes
1answer
82 views

Is it good idea to set custom-defined getter and setter in c#?

I tried this way to define custom defined property but I wonder how to handle if any of the dependent properties have null value. public class ObtainedMarksDetail { private decimal? ...
1
vote
1answer
36 views

Paging params - domain repository interface

I usually define my repository interfaces at Domain Layer with DDD. Given that the UI needs to display some paged data I thought that adding params such as currentPage, pageSize, and define a model ...
-1
votes
2answers
82 views

Should integration tests use database? [closed]

I know that integration tests test parts of project that interaction with each other somehow. And I need to test this interaction. And there is the question: 1)Should these tests use real database ...
2
votes
1answer
74 views

params T[] vs IEnumerable<T> as parameter type

I know there's a proposal for params IEnumerable<T>. When designing an API, when should we choose params T[] (params array) over IEnumerable<T>. Or should both be implemented for better ...
1
vote
3answers
127 views

Always return the parameter when it has changed inside the method?

When you have a method that is doing stuff and changes occur in the parameters, should you always return the changed object like this: public SomeModel DoSomething(SomeModel someModel) { [something ...
-2
votes
1answer
53 views

Method that takes array parameter [duplicate]

I want to implement two methods: AddPlayers and AddPlayer. Is it better when AddPlayers calls AddPlayer or AddPlayer calls AddPlayers with a single item array? Is there a significant difference in ...
3
votes
3answers
144 views

Is checking if something exists responsibility of a caller or an API?

Is it better for an API when it provides additional methods that check if something exists before adding? For example: if (!userManager.HasPermission(user, "somePermission") userManager....
-2
votes
1answer
49 views

Using Automapper in Presentation layer while keeping logic in ViewModels [closed]

Using Automapper in each of my layers to do the boring mapping. However, one thing I haven't solved is how to use AutoMapper to map from DTOs in the Application Layer from my QueryResults to ...
1
vote
1answer
58 views

Calling executables from an ASP.NET WebAPI

I have an Angular application with a table, and I'm considering having the console application take the name of C# programs that the user can run. I was thinking of passing the name or code of the ...
1
vote
1answer
54 views

How to propagate Setting Class throughout entire project

Here's my setup: Entity Framework Backend Large WPF project that has a main window with 3-4 user controls on it, each of which has 3-4 user controls on it (and so on, in some cases) What I currently ...
0
votes
2answers
40 views

Methods taking parameter of Collection should filter the collection themselves or be passed a filtered collection?

Say I have this reasonable contrived situation: public class Toast { public bool Toasted { get; set; } public int MinutesToHeat { get; set;} } public class Toaster ...
101
votes
5answers
9k views

Aren't the guidelines of async/await usage in C# contradicting the concepts of good architecture and abstraction layering?

This question concerns the C# language, but I expect it to cover other languages such as Java or TypeScript. Microsoft recommends best practices on using asynchronous calls in .NET. Among these ...
1
vote
1answer
89 views

Handling multiple game modes with a game controller

I have a basic GameController with a finite state machine to handle game logic. I'm adding game modes and coming across problems cleanly implementing them. The core functionality of the game stays ...
-1
votes
1answer
78 views

Would I need a web framework if the app is running locally and not in the net?

I need to make an Employee Payroll application and the client specifically stated that the application will run on their computer locally and will not be hosted anywhere in the internet. I can code ...
3
votes
4answers
328 views

How to avoid excessive downcasting when using inheritance

I'm coding a game and I have a design issue in which I have a superclass which all items in the game inherit from. The game is grid based, and the items can be placed at different parts of the grid. ...
1
vote
1answer
85 views

Refactor asynchronous code in C#

I got the following code snippet: public Task DistributeAsync(BankAccount account, decimal amount) { lock (account) { return repository.AddLoanAsync(account, amount).ContinueWith(task ...
2
votes
4answers
205 views

C# class naming convention for a single item in the item list [closed]

In my C# project, I have a domain class named 'User'. this class will contain user's id, firstname, last name, DoB, home address, phone, etc. And we also have a typical REST web api (i.e. api/users) ...
4
votes
2answers
224 views

Injecting a dependency that is a tree of dependencies

Is it a pattern or antipattern to inject a dependency that is a tree of dependencies? For example: public class ClassExample { private IContainer _container; public ClassExample(IContainer ...
2
votes
1answer
104 views

Should .NET Core class libraries register their own implementations?

Our team had recently a big struggle of deciding whether it is a good practice or not for the .NET Core class libraries to register their own implementations by the fact of providing a ...
0
votes
3answers
99 views

Should I reuse a predicate for multiple IEnumerable checks

In a long running Windows Service I have a custom thread pool manager that has a loop which continuously looks through a couple lists for idle threads. Given multiple uses of the same predicate, is ...
0
votes
1answer
83 views

C# Unit Testing: Mock a Return Type

What is the best way to Mock a return type if we don't care about the actual state of the object. For example, I am Mocking a method whose return type is: IEnumerable<Document> Now, I can add ...
2
votes
3answers
283 views

Workaround for no methods in namespace in C#

I am new to C# and have a difficulty with the code structure. My application has: GUI with button Show my Ethernet IP. When user clicks this button PC's IP address is displayed. Class ...
1
vote
3answers
116 views

Should Data Access Layer surface return Data Transfer Objects or return EF Models?

So say I have a controller Method // GET: TimeEntries [HttpGet("[action]")] public IEnumerable<TimeEntryDTO> GetLast(int value) { return dal.GetLast(value); } And a ...
1
vote
2answers
202 views

Clean architecture, CQRS, and authentication?

I'm working on implementing my first clean architecture and CQRS application, I've stumbled across a bit of logic that's leaving me a bit stumped. I'm working on integrating authorization and ...
1
vote
1answer
137 views

c# What problem will happen when i use static class for access database?

Many place that i have read about static method they said please shouldn't use static method for access to database and should use dependency injection for inject other service and use that service to ...
0
votes
2answers
173 views

Uncle Bob's clean architecture refactoring techniques for data objects / entities / LINQ queries

I have relatively simple controller logic with ugly parts of object creation. Some of the objects are really huge and even though all the controller does is to return the object, it looks messy and ...
2
votes
0answers
171 views

LSH for a wordlist

I am trying to write a spellchecker, I have a huge wordlist (at least 500K, because of the nature of the language). The performance would suffer a lot if I got the lavenshtein distance of all of the ...
0
votes
1answer
80 views

Mediator pattern across web API

What are your thoughts on mediator pattern being used from a client and across a web api?, this means: Command definitions are shared between the client and api. Web api exposes only one ...
34
votes
4answers
6k views

Is it enough for methods to be distinguished just by argument name (not type)?

Is it enough for methods to be distinguished just by argument name (not type) or is it better to name it more explicitly? For example T Find<T>(int id) vs T FindById<T>(int id). Is there ...
0
votes
1answer
62 views

Binding to Task<T> property and seting IsAsync to true

I'm trying to figure out a good way to bind the view to viewmodel properties that needs to be populated using an async method. The latest I got is using IsAsync like so. ViewModel.cs public class ...
1
vote
1answer
68 views

Where and how to handle user password hashing in Clean Architecture?

I'm currently building a new application and trying to apply some of the principles of Clean Architecture. One of my first roadblocks is implementing my own Identity system (to avoid being tightly ...
1
vote
5answers
156 views

Correct usage of HTTP VERBS in custom REST implementation

I have a server-side service (using ASP.NET Core) that should provide a REST API to various clients. Behind the service, I use a SQL server for data storage. The controller has the following route ...
0
votes
2answers
103 views

Naming conventions for .net C# Unit test projects for better sorting [closed]

I currently use the following naming scheme for my unit test projects.. if I have a project "MyApp", I will have.. -- MyApp -- MyApp.Tests I see this is quite a common practice. Now, the problem is,...
3
votes
3answers
234 views

what is the best way to write a recurring code with different enums

Basically what this code does is to determine whether the user is allowed access to the page or not from list of pages as enum, each one has the role name as its name and the page name inside it. The ...
1
vote
2answers
142 views

Encapsulation and input validation duplication

Consider the following example (very simplified): public class Basket { private readonly List<BasketItem> _items = new List<BasketItem>(); public IReadOnlyCollection<BasketItem&...
0
votes
3answers
63 views

Nesting Objects without Passing Arguments?

I have a couple of classes that I've nested together (not in the sense you may think so bare with me), to create what I call a prefab object (similar to Unity's prefab system). In this particular ...