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
28 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
117 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
71 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 ...
7
votes
3answers
281 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
23 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
71 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
35 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
77 views

Should integration tests use database? [on hold]

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
68 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
119 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
50 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
139 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
48 views

Using Automapper in Presentation layer while keeping logic in ViewModels [on hold]

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
51 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 ...
99
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
76 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
317 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 ...
0
votes
0answers
26 views

WCF service contract for dynamic response based on input request. C# [closed]

Below is a sample format of response and equivalent service contract of my web service looks like. <Players> <Player> <Name>Sachin</Name> <Sport>Cricket</...
2
votes
4answers
201 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
218 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
102 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
98 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
77 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
277 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
110 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
174 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
136 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
170 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 ...
1
vote
0answers
167 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
79 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 ...
33
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 ...
-3
votes
0answers
51 views

Scheduler that goes through thousands of data every 10 minutes, is it better to do recursively? [closed]

I have a scheduled task that runs every minute, that processes thousands of data. It is currently programmed this way: var data = _context.jobsData.Where(predicate).ToList(); // query usually ...
0
votes
1answer
59 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
64 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
154 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
97 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
232 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
140 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
62 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 ...
1
vote
1answer
138 views

Is this a valid site architecture?

We have a legacy site that was written a while back using MVC. It's a valid MVC for the most part except for the Data Access Layer. The site has Models, Views, and Controllers. However, instead of ...
0
votes
0answers
95 views

Software Architecture with C# and WPF

We have the need to develop an offline desktop application for a measurement equipment. While having quite a bit of experience in C++, We are new to WPF and VS in general. This software will have a ...
1
vote
1answer
64 views

Managing heterogeneous data

The underlying problem is one I seem to run into a lot. You have a collection of objects with some things in common, but other information about the objects may apply to some of them but not to others....
3
votes
3answers
241 views

When to use xxxResult return value pattern?

I have one method which need to return multiple values whether it was successful or not, what the key used to call the api and if successful the return result. Here is more concrete method, public ...
0
votes
1answer
142 views

DDD - Factory or Service?

I'm new to DDD, and I'm confused at the very start of my DDD project. To setup a context, I'm building the user management part of my app, so I'm building my Account entity, which contains an Id, a ...
2
votes
1answer
63 views

Redesign Issue (Multiple Inheritance without Multiple Inheritance)

I am currently working on a game engine for work and have hit a wall on my idea. I have multiple objects (called prefabs) that have very common properties such as Position, Rotation, and Scale. There ...
-1
votes
1answer
90 views

Downcastings refactored using generics

I am willing to refactor some code that acts like a controller class executing work embedded in other classes. On one side it looks good as the controller is generic and what changes has been well ...