Questions tagged [c#]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
104 views

How to follow execution path of a Unit Test in real time without manually stepping through the code line-by-line?

I'm using MSTest. I have some async functions I'm unit testing that rely upon a lot of different methods where the result needs to be awaited upon. Sometimes the unit tests stall in a "running" stage ...
-2
votes
1answer
96 views

Is this OK to call a method that subscribe to IObservable multiple times? [closed]

I have this method: private void ModerateTravel() { var vm = new ModerateTravelViewModel(); moderate.ShowModerateTravel(vm); Observable.FromEventPattern<string>(h => vm.Error += ...
-2
votes
1answer
90 views

Centralized REST API call management?

I was given a solution with many projects. Multiple projects call multiple REST APIs. These calls are scattered around the spaghetti code. Trying to figure out what calls are done in what sequence ...
9
votes
2answers
297 views

How to design microservices with large number of joint entities outside of the domain border?

I'm working on breaking down a monolith application in smaller applications or microservices. Like always, sometimes it's easy and sometimes it's harder to identify domains and split those into ...
2
votes
2answers
257 views

C# - Correct way to convey Null Object design pattern via an interface for client/service?

I've just learnt about the Null Object design pattern, which recommends that the service either return a default null object or throw an null related exception itself so that the client need not worry ...
4
votes
4answers
357 views

Grouping of methods

We have multiple pages searching for users, each site having different search parameters. Sometimes, we have 2 parameters, sometimes 4 and most of these parameters overlap. So we have kind of (...
2
votes
1answer
332 views

How to parse a dynamically changing Json file? (c#)

So I know a little bit about parsing Json data but not too much so pardon if I am not describing everything as I should. Lets use this Json file as an example: { "firstname": "John", "...
0
votes
2answers
124 views

C# - Generic Configurable Condition checker at Runtime - Achievement System

I'm writing a "generic" achievement system for my MMORPG project, it needs to be friendly & efficient for my game designers (without having to write code to add new achievements). If anyone got ...
0
votes
1answer
64 views

Unit testing async tcp server

I built an async multi-client TCP server for RPC usage. It's working well but I've found it difficult to unit test certain functionality: Connect 2x clients, is client count 2 Connect 1x ...
2
votes
0answers
181 views

Should developers do things that defeat strong-typing, kill intellisense and make it difficult for other developers to follow? [closed]

Just to clarify: This is not a rant. I'm genuinely curious and it's a genuine question our of straight curiosity. I want to become a better developer and even little details like this count. So, don'...
1
vote
2answers
384 views

Is there a best way to insert variables into strings?

I am relatively new to programming but have noticed a lot of people when creating strings using variables do something like the below to put a variable into a string. I am curious at the difference/...
0
votes
1answer
120 views

Architectural pattern for testable C code [closed]

I wrote a lot of software in C# and Python. I tried to make the overall architecture testable by using the "Clean Architecture" and Dependency Injection. This works well for C# (and python). Now I ...
11
votes
5answers
2k views

Looking for an effective pattern to cope with switch statements in C#

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
-2
votes
1answer
76 views

Are These Both The Same Or Different If Statements [duplicate]

This is for unity I tried another way of stopping player after he dies and it worked fine but now it does not work with sounds That was my way the only thing that I changed is the state Ben's was ...
-2
votes
3answers
205 views

Best Practices for Managing SQL Code

I have a issue that keeps coming up as a developer using any .NET (C# mostly) and SQL. I personally feel it is bad practice to build SQL statements in code. There are too many case scenarios that may ...
0
votes
1answer
98 views

Create or Update method returning created entity

Clarification question on saving entities best practice. What is the purpose of returning an entity that you might have just saved in a repository? I see the benefit of returning it's Id once it's ...
0
votes
1answer
99 views

GraphQL results in a very large Query and Mutator file for Enterprise Monolith

I am investigating a good maintainable architecture for GraphQL. In particular we want to migrate a REST app to GraphQL. Specifically I am using .NET. I am following the tutorial here: https://...
82
votes
9answers
17k views

When to use / not use syntactic sugar

Currently I am working on a school project written in C#. Some teammates just started in C# and some are already familiar with C#. Today I had a discussion on whether to use syntactic sugar like this ...
1
vote
0answers
110 views

Application Service Layer referring to two Layers, and Database Entity Copy Layer with DTO Layer?

I am trying to review our current architecture. These are the current layers, trying to analyze them, and see if the following three ideas are good practice. DatabaseSQLStorage ---> Entity Framework ...
-3
votes
1answer
152 views

A True RESTful API | Help needed

I know that a RESTful would have unified API and it treats everything as a resource (a noun, example a book, a product,...) and it can be applied with CRUD operations using HTTP Verbs (GET, PUT, POST, ...
1
vote
2answers
72 views

Custom services container for ASP .NET core business layer

My model classes (business layer/library of ASP .NET core solution) uses a number of services (IOrmService, IEmailService, IFileService, IHtmlToPdfConverter etc.). Different models requires different ...
2
votes
2answers
149 views

Copy Database Entities into Another Layer in Software Architecture?

We are using Entity Framework with SqlServer Database. Business program needs to create many columns which are not in the Database, due to storage, high querying cost etc. Currently, the team is ...
0
votes
0answers
68 views

Instantiating adapters in onion architecture

GitHub and NuGet Do you use connection strings to instantiate your adapter services or just always configure it through IoC? I think that connection strings could provide a way more flexibility, ...
2
votes
4answers
222 views

Is having different implementations for ToString and the implicit operator bad design?

I am currently developing a wrapper API for a translation service that should provide multiple methods for translating strings, Task<string> ITranslator.TranslateAsync(string phrase, Language ...
0
votes
2answers
132 views

Is it ok to use .Replace(“ ”, “+”) when reading hashes in a querystring?

I am letting users change their password after a reset, by following a link containing hashes of the password and user name (e-mail address). The link can look like this: www.example.domain/login?...
-4
votes
4answers
145 views

C# Why should i limit myself to List or Stack ? ( instead of having both)

List is implemented in C# exactly as Stack, see: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.stack-1.push?view=netframework-4.8#remarks https://docs.microsoft.com/en-us/...
0
votes
3answers
194 views

How to inherit a static function in a class?

Probably the answer is you can't. However, I would like to have a work-around to solve my problem. Objective I am trying to create a program in which I try to avoid nulls as much as possible. ...
1
vote
2answers
226 views

Why can't I use a generic method to implement multiple typed interfaces in C#?

public class B { } public class C { } public class D { } public class E { } public class A : IRetrievable<B, C>, IRetrievable<D, E> { public TValue Retrieve<TKey, TValue>...
0
votes
2answers
326 views

How to avoid deadlock

I have queue of MoveableItems in a class BackgroundTaskQueue (based on example from Microsoft here). Clients call BackgroundTaskQueue.QueueBackgroundWorkItem to add a MoveableItem to the queue. An ...
2
votes
3answers
120 views

Is it ok to have a DTO for each process/app/service in a system?

I have a Foo service that, among other things, retrieves data from a table called Widget. This table has about 50 columns. This service is called by a request from a browser. Now, I have another ...
1
vote
2answers
274 views

How to avoid magic strings when doing Translations

I have worked in companies that to achieve translations based on the user's localization they use a file to store those translations. However, when they try to access a translation on that file they ...
2
votes
1answer
67 views

What are some authorization based design patterns to limit functionality from the perspective of size or amount of data?

I am well aware of role based / activity based authorization in the context of limiting user functionality in a simple on/off manner; however, the problem gets difficult when it's not so black and ...
1
vote
4answers
827 views

forEach over branching over null check?

I was watching Zoran Horvat's "Making Your C# Code More Object-oriented" on pluralsightpaywalled. And he says that instead of : if(obj != null) { obj.DoSomething(); } We should have a list that has ...
1
vote
1answer
113 views

Include Get Password function in User Domain without violating separation of concerns

Problem: I am using a Domain Driven Design architecture and I have a domain model called User as follows: public class User{ public User(string username){ this.Username = username; } ...
1
vote
2answers
114 views

How to concat lists with logical ANDs and ORs

Having multiple lists of integers, like e.g.: var p1 = new[] { 3, 9, 5, 8, 9 }; var p2 = new[] { 12, 1, 18, 27, 103, 99, 4 }; var p3 = new[] { 23, 930, 15 }; // ... I want to concatenate them with ...
0
votes
0answers
43 views

Effective data/rows queuing out of database

A component in a system (called Notifier) inserts hundreds of messages ~300 (SMSs) per second in a table in MSSQL database with PENDING status by flagging a column called status with int value 0. ...
-2
votes
1answer
58 views

Creating one or multiple objects based on the input

I am designing the software to calculate employees' hours among others. To simplify my problem let's say that I have Activity class, which has a property Type. This type could be for example "Standard ...
0
votes
2answers
163 views

Simple Poker Simulation - How to design it well

I trying to create a little poker Texas Holdem simulator .. In my solution have some class : Premise : I know about Fisher Yates algorithm. I will implement it later Keep in mind that the next ...
-3
votes
3answers
272 views

Better way than singleton pattern to ensure single instance of class

When this question has been asked before on StackOverflow in 2011 and 2015, all answers as of now suggest to use a Singleton. But that’s not right. Singletons are defined by the Gang of Four to ...
8
votes
3answers
926 views

How can we avoid showing the literal path in the exception's stack trace?

When our in-house developed application (C#, ASP.NET) is throwing an exception, it displays a stack trace that contains path information like C:\users\DEVELOPER_FULL_NAME\path\some-module.cs. So it ...
-1
votes
1answer
76 views

How can I securely store and process user data?

I am creating a Discord Bot in Discord.Net. So first, of course this bot is not a professional project, but I still want it to look as professional as possible. And a huge part is the storage and ...
0
votes
2answers
58 views

where to put presentation data formatting method

I am trying to display a specially formatted dropdown list as part of a view. I have a controller action which fetches the data for the dropdown, then needs to format it by fetching certain other ...
2
votes
3answers
188 views

Should a library throw exceptions that reveal its internal call stack?

While researching this question, I've found a lot of sources like this: Basically, it should be deemed a criminal offense to use "throw ex". The experts I'm seeing this from seem to be working ...
2
votes
3answers
150 views

Why does imprecision fail for these 3 numbers specifically?

Hi i asked this question on SO but no one seems to be bothered to answer the question with actual information. Firstly just to say, i fully know computers are imprecise for floating numbers and ...
1
vote
2answers
123 views

Payment system migration

GitHub There need to be a software design supporting gradual migration from one payment system (E-xact) to another (Stripe). Credit cards data are stored outside, so I would like to use both systems ...
1
vote
1answer
127 views

Create a common interface to use N libraries and define specific behaviours

I am creating a browser automation library that is capable of using Puppeteer(automates chromium) and Selenium(automates all major browsers), but the goal is to also be able to add more libraries in ...
0
votes
2answers
85 views

Layered Model-View-ViewModel design

I am designing an application using C# and Windows Presentation Foundation (WPF). I would like to follow (at least) the very basic rules of software architecture, like dependicies only going in one ...
1
vote
2answers
188 views

What's more expensive on my server-side processing?

So I want to be processing my security protocols server-side, mainly token checks and then role authorisations for certain actions. I'm using c# .net core connecting to an MS SQL database and ...
1
vote
4answers
1k views

Throw an exception in default case of a switch?

In my class I have a processor manager that contains a switch case. I just renamed the real name by Ant, Parrot and Snake. switch (name) { case "ant": ...
2
votes
1answer
83 views

Application Security Trimming vs Database Security Trimming

We have a fairly complex Meetings Management solution which would have one meeting to contain different agendas which would contain some tasks and also documents, etc. There are also different roles ...

1 2 3
4
5
90