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

-2
votes
1answer
34 views

What should I test with unit tests for data access layer? (MongoDB)

Well, I'm working in TDD for my data access layer (MongoDB) And I don't know what I should test I think that I shouldn't test if the queries return what They have to return because It's a MongoDB ...
0
votes
0answers
17 views

C# TcpClient and NetworkStream to write and read data over TCP

I am trying to write a method that will format message (as flat-file fixed length message), write it to stream and read response from host like I have it below. While this seam to work, I am not sure ...
-1
votes
0answers
24 views

Subscription based notification implementation

I want to implement functionality similar to the Azure DevOps subscription notification where you can define criteria for subscription and sending the email notification. I was thinking of creating ...
0
votes
1answer
68 views

Calling same method on different instance (Polymorphism)

I have situation that 3 different instances with the same method signature are doing their job repeatedly. interface IArgs{ //args stuff } interface IExample{ void Populate(IArgs); } class ...
0
votes
1answer
112 views

Methods linking bad/good practices

I have multiple methods calling each other to simplify changing anything in the code and to avoid fixing errors and copy pasting. It looks like this: Is this a bad practice? Does it cause too much ...
0
votes
0answers
36 views

Should AutoMapper be used to Map from ViewModel back into Model?

Should AutoMapper be used to take data from ViewModel and save back into a database model? I know the opposite practice is good software practice: to have Automapper to extract database models, and ...
3
votes
1answer
153 views

Propagating Data to multiple ViewModels - C#

I'm a bit new to MVVM, but here's my dilemma: I have a model (or models, but let's keep it simple) I want to show that model data on multiple different views. Ok, so ViewModel for each view gets ...
45
votes
12answers
19k views

Avoiding the `goto` voodoo?

I have a switch structure that has several cases to handle. The switch operates over an enum which poses the issue of duplicate code through combined values: // All possible combinations of One - ...
1
vote
0answers
58 views

Reducing dependencies between stories & which branch (GIT) should QA's test on?

Background We have a team of 8 devs and 1 QA (tester) and we're struggling with dependencies between tickets and causing a lot of merge headaches and/or people waiting around for the next bit of work ...
-2
votes
0answers
48 views

C# enum using switch statement - how to use user input [migrated]

While trying to learn C# Im trying to play with Enum and switch statement. how can I pass the user input into a variable in order to let him select one of the options in an enum? what is the right ...
0
votes
0answers
59 views

How to leverage generics to populate derive class models to avoid code duplication?

I am having 2 types like and each type have different processing logic. Based on that processing I am preparing a result and returning it to the consumer (mvc application,console app etc..) Type 1 ...
-2
votes
0answers
57 views

C++ code generation [closed]

I need to generate C++ code (headers and implementations). I would like to do it in C++ or C#. I can think of: Simply appending to string or writing to file directly Template-based approach (using ...
1
vote
1answer
35 views

Best practice with SignalR communication

I'm working on a project that involves online purchases. I have my web api in C# and my client in REACT (javascript). Server and client are connected with SignalR. I want that when an ORDER is ...
3
votes
5answers
259 views

How to Differentiate Unit Tests from Integration Tests?

In my C# solution, I have a Tests project containing unit tests (xUnit) that can run on every build. So far so good. I also want to add integration tests, which won't run on every build but can run ...
0
votes
0answers
30 views

Frontend JSON payload that defines which classes to use in the backend

Payload: { "selection": { "ids": [1,2,3,4,5] }, "image": { "backgroundColor": "#FFFFFF", "headlineColor": "#000000", "format": "PNG" }, "processors"...
2
votes
2answers
183 views

Should Entity Framework 6 not be used with repository pattern?

So I am asking this after reading the following: Why shouldn't I use the repository pattern with Entity Framework?. It seems there is a large split of people who say yay and those that say nay. ...
2
votes
1answer
100 views

Long running server process. How to update client

What I'm looking for is a pattern for the client triggering a server process, then the server process signalling the client when its finished. preferably with examples available in .NET or dotnetcore ...
3
votes
1answer
371 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 ...
4
votes
4answers
22k views

Practical size limits of a DataTable in c#

I have to query a large data-set (~500 MB) using a sqlDataReader but I have to save the data in three different formats. Instead of querying the database 3 times I'm thinking about saving the data to ...
3
votes
6answers
198 views

Should I use entity framework for CRUD and let the database handle the complexity that comes with high end queries?

I am new to ef and liking it since it reduces the overhead of writing common queries by replacing it with simple add, remove functions. Agreed. Today I got into the argument with my colleague who has ...
0
votes
2answers
3k views

Entity framework vs pure ado .net in calling stored procedure in an enterprise project

There is an enterprise project, which all the business implemented in databases and in the stored procedures, and web API is just like a light wrapper which get the request and deliver it to proper ...
0
votes
1answer
51 views

ASP.NET Core - Is using [FromServices] attribute bad practice?

I have a Controller in ASP Core MVC. I'm trying to trim down the dependency injected services in the constructor so I can start building unit tests more easily. However, I have some services being ...
61
votes
12answers
9k views

Having a flag to indicate if we should throw errors

I recently started working at a place with some much older developers (around 50+ years old). They have worked on critical applications dealing with aviation where the system could not go down. As a ...
0
votes
3answers
101 views

xUnit Should I Test Method Internal Work Or Only Result?

Let's take this unit test. Unit testing guidelines state that I should only have 1 assert per test, unless I'm testing the state of an object. In this case, Muxer.Muxe is a wrapper around FFMPEG that ...
-3
votes
0answers
63 views

OOP C#, Java, How should many classes and objects communicate to accomplish a task? [closed]

If we are following the single responsibility principle then a big program should have hundreds or thousands of classes, however I've yet to find an explanation on how exactly these 100-1000s of ...
-3
votes
0answers
117 views

C#: is it possible to define a list of object types to use as argument?

I am working in C# (Windows Forms app) and I am making a 3-layered application. The problem I have stumbled upon is the communication between the UI and the BLL. The application copies/manipulates/...
3
votes
1answer
158 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). ...
0
votes
1answer
46 views

Entity Framework and static entity instances

I'm always having the problem on how to properly design having static entity instances and it being attached to Entity Framework's Dbcontext. For example, we have the following: using Microsoft....
3
votes
3answers
397 views

How to decide, should I put methods to abstract class or to interface?

I'm writing an app it needs to have generic registration step item. It needs to be able to do some specific things (I use interface for that) and it needs to be a visual element (of Xamarin. It doesn'...
-1
votes
0answers
52 views

Choosing between database file storage and file system storage [duplicate]

(repost from https://stackoverflow.com/questions/54590899/choosing-between-database-file-storage-and-file-system-storage) This question might be asked a lot of times, but I couldn't find the solution ...
3
votes
1answer
77 views

Using Active Directory ObjectSid as Primary Key in SQL Server for Data Access via ASP.NET MVC

I am designing an Intranet employee reward web app using ASP.NET MVC C#/MS SQL Server. This will only be accessed from within the network. Employees and managers will be able to give a reward to ...
5
votes
4answers
378 views

Replacing Linq Methods with Extension Methods

So, I've fallen into the fad trap, and started replacing a large amount of linq queries with extension methods. For example: orders.Where(o => o.Status == ShippedStatus.Shipped).Select(o => o....
1
vote
3answers
143 views

Calling full functionality private functions from public functions

I have been programming my classes in the following mode. I create a public function that has a call to a private function that has all the logic and functionality. Something like: public class ...
139
votes
8answers
142k views

How do you organize your projects? [closed]

Do you have any particular style of organizing projects? For example, currently I'm creating a project for a couple of schools here in Bolivia, this is how I organized it: TutoMentor (Solution) ...
2
votes
2answers
180 views

Single responsibility principle - importer

I'm writing an importer, it should fetch some data from the database and put that data into appropriate places. Now the question is, should the importer itself fetch that data, or should that data(to ...
-2
votes
1answer
277 views

Server initiated communication to clients

I am trying to build an internet service that executes commands on the connected computers. Commands are initiated through a web-based dashboard. I currently have a REST API running with Laravel and ...
0
votes
0answers
58 views

Onion Architecture - Input Validation X Model Validation

Based on the project structure below I will have some questions, but one important thing is that I'm not working with DDD Domain Layer 1) MyApp.Domain.Entities (DLL) public class Product : ...
0
votes
1answer
70 views

Factory Design Pattern Implementation with multiple interfaces and base class

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
1
vote
1answer
132 views

Keeping steps in sync of long running process and creating common layer for code repetition

I have 1 long running process wrapped inside a method and it is for 2 different types like below: Type1 Type2 Code: public interface IBaseType { MyResult LongRunningProcess(int jobId,...
1
vote
3answers
108 views

Should we inherit from base class and implement interface in this scenarios?

I am new to object oriented design and learning about interfaces and design patterns. In this example, I am trying to create class for cars. My question: Is it good practice to use base class and ...
0
votes
1answer
97 views

Two reversed dictionaries or one dictionary with key and value lookup?

I have situation where in the Repository class I have a dictionary: Dictionary<TableName, Dictionary<EntityColumnName, SourceColumnName> map1 = new Dictionary<TableName, Dictionary<...
-6
votes
0answers
66 views

Need help with parallel processing [closed]

I am trying to create a very basic tool which would execute a script, retrieve the data and then write it into CSV. This needs to be done across 5000+ database servers. This can definitely be improved ...
14
votes
5answers
4k views

Pass object twice to same method or consolidate with combined interface?

I have a method that creates a data file after talking to a digital board: CreateDataFile(IFileAccess boardFileAccess, IMeasurer boardMeasurer) Here boardFileAccess and boardMeasurer are the same ...
0
votes
3answers
139 views

How can I interpret a SQL Check Constraint inside my C# .NET class libary?

I was given a more or less complex task. The goal is to interpret a SQL Check Constraint inside my C# .NET libary. In our case we have a simple UI that displays what is inside the database. We do not ...
0
votes
3answers
97 views

Should I create a shared Test Initilization object to initialize multiple test classes?

Scenario I'm a new developer, using MSTest and I've encountered the following issue: SomeClassTest // Uses a Fake Widget Controller. Test Initialize { Many lines of code to initialize Fake ...
2
votes
1answer
110 views

Design pattern for an indeterminate number and format of questions

In my application, I have a finite number of question types, but the order in which they're asked and whether they're asked at all is not known up-front. An example analogy is a hotel booking process,...
2
votes
2answers
98 views

Queueing async code to execute later

I have a website with basic crud operations that involve data and photos. I also need to extract the metadata for the photos that are being uploaded. My original implementation did not have var puts =...
0
votes
2answers
135 views

What HTTP action and return value should be used on resource's action

I have a question about how I should implement a new action for a resource on my API layer. I have a Timesheet which is used by people to let us know how many hours they worked on a job. This ...
1
vote
2answers
188 views

How to find already existing code | How to arrange code in a way it can be found again [closed]

I'm refactoring the framework of our company, trying to fix the issues we had in the past. We're a team of 6 developers, and we have various needs and issues in regards to tidying up our framework. ...
16
votes
1answer
3k views

Why were magic methods implemented in C#?

In C#, I started seeing all these magic methods popping up, without being backed up by an interface. Why was this chosen? Let me explain. Previously in C#, if an object implemented the IEnumerable ...