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
-1
votes
4answers
125 views

Which is better if(condition == false) or If(!condition) [duplicate]

I have always written my if statements like this when I want the negative condition to enter me into the if block. Example 1 if(condition == false){} However, we just hired a new senior on the ...
1
vote
0answers
62 views

How to design the interface method for the following case?

I am making a Snmp agent. In order to pass information to this Snmp agent I need to periodically extract data from two different sources and there can be more sources in future. I was designing the ...
2
votes
4answers
192 views

How do you assess the damage in a system that has been using floats or doubles for money?

I've been assigned to a code base responsible for millions of dollars of transactions, per quarter, and has been in use for over a decade. Sifting through the solution, I see doubles used everywhere ...
1
vote
1answer
83 views

Calling a private method in a setter to update object at every change of the property

Code below shows setting a value of an object's property and calling a private method in a setter to update the status of the object. Is this call a good practice or setter at most should only ...
1
vote
1answer
33 views

Finding Event-Oriented Patterns in temporal sequence

I have a 24 hour "sliding window" sequence of "start" and "stop" events in memory comming from an iOT device. I'm only interrested in finding "stop" events followed by "start" events in order to ...
0
votes
3answers
141 views

Should I make the class static or non-static for the following case?

I have a class which has the purpose of providing file operations i.e. providing functionality to create the file, read, write and rewrite to the file. So, the main constituent of the class is ...
1
vote
3answers
223 views

Feature toggle: How to toggle without spreading same toggle all over the code?

Considering a feature needs changes at many places in different modules of the software: UI, business logic, backend, etc. What is a good approach to do so? We are using dependency injection and ...
-1
votes
3answers
57 views

Using a separate desktop application for handing scheduled tasks in an ASP.NET MVC Application

I have an ASP.NET MVC application and I will need to execute a task every one minute. The task is: -> Go to database -> Check from Table 1 if a record has value = "something" -&...
2
votes
3answers
145 views

Micro services communication among them

I am converting a monolith to micro services architecture using RESTful apis using C#. I have identified various micro services that will completely represent my monolithic application. One important ...
0
votes
0answers
58 views

Can a C# AnonymousPipeServerStream create a non .NET client?

For example, if I want to write a daemon program in C# that uses anonymous pipes to communicate with programs written in another language, is this both possible and feasible? I ask because I intend ...
3
votes
1answer
89 views

Difference Between AsyncResult and Task in c#

So, in C#, I understand the historical difference between the two vaguely; a Task is a newer concept and the highest level concurrency native C# offers. AsyncResult is a bit more ambiguous. For ...
6
votes
4answers
288 views

Exposing implementation details to tests

I have created a class that implements behavior which is difficult to test without some intimate knowledge of internal state. I'd like not to clutter the class's public API with accessors for this ...
3
votes
1answer
99 views

How to maintain Depedency Inversion Principle with enums & custom types?

From what I understand two components A and B should only communicate with one another via an interface. Ideally this interface should be in its own separate assembly so that the client need not be ...
1
vote
2answers
234 views

Common interface to handle different data type

I have a design question about data. I have a class "T" that has a single interface handling two data types as described below. The class T is constructed to handle one of the two data types. Users of ...
1
vote
1answer
123 views

Where to execute domain validation which is not part of domain object?

I'm not sure where to place the following checks I have now in the material domain class. The issue is, that I need to validate that material exists and is valid in external database. Only after that ...
1
vote
1answer
185 views

Program Structure

I'm looking for general advice regarding the structure of applications. In applications I've been building recently, I've started to use a class (I'll refer to it as DataManager for the rest of the ...
21
votes
4answers
4k views

Constructing an object: should I expose or hide parameters passed to the constructor?

I've a habit I just mechanically do without even thinking too much about it. Whenever a constructor is waiting for some parameters, I consider this a public information that should be available by ...
3
votes
2answers
157 views

When to use third-person verb? (PlayOnAwake or PlaysOnAwake)

First a couple of examples: var val = obj.GetValue(); var can = obj.CanPlay; var has = obj.HasValue; var val = obj.RequiresConstantRepaint(); // From Unity var val = obj.PlayOnAwake; // From Unity ...
3
votes
3answers
226 views

Struct or class for wrapping an int when 0 isn't a valid value

I have a business object which is basically a wrapper around a value of type int. There are some constraints for the value/object: Not every value in int's range is valid1 The valid values are not a ...
57
votes
8answers
9k views

How do I ensure that interface implementations are implemented in the manner I expected?

Let's say there is a member SomeMethod in an interface ISomeInterface as follows: public interface ISomeInterface { int SomeMethod(string a); } For the purposes of my program, all consumers of ...
1
vote
2answers
101 views

Refactoring multiple for loops on same list in different methods

I have a code that is something like this in a class string method x (){ foreach(a in alist){ //do something } return string; } integer method y (){ foreach(a in alist){ //do ...
-3
votes
1answer
314 views

C# is fantastic, if only List 'd respect Remove&Return [closed]

In the domain of system-modeling (e, systemVerilog, matlab, phyton), lists are obsoleting arrays, stacks and queues(*) altogether. Other domains that use python, perl and ruby have that same mindset, ...
1
vote
1answer
436 views

Microservices and 3rd party APIs

I recently joined a team who is trying to use "microservice" pattern for their new application. They've already started to implement API's. In the end it should be an API for both mobile and web UI. I ...
0
votes
2answers
153 views

Avoid framework lock-in with dependency inversion

I am trying to understand the concept of dependency inversion and I think I finally got the concept. However now I am struggling with another issue, which is the selection of framework, when ...
2
votes
1answer
101 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
93 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
69 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
274 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
167 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
304 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
112 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
82 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
47 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
178 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
345 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
109 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
4answers
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
70 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
2answers
157 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
93 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
51 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://...
79
votes
9answers
16k 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
68 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
149 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
67 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
130 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
63 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
207 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
131 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
137 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/...

1 2 3 4 5 87