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
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 ...
-2
votes
0answers
47 views

C++ code generation [on hold]

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 ...
0
votes
0answers
26 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"...
1
vote
1answer
29 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
188 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 ...
-2
votes
0answers
38 views

C# Consolidate multiple console applications into one [on hold]

We use numerous c# console applications in our organizations. Each application and developer are writing console applications for their needs and schedule those using Tidal etc. Is it good idea to ...
2
votes
2answers
161 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. ...
0
votes
0answers
55 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 ...
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 ...
3
votes
1answer
88 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
0answers
58 views

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

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
114 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/...
0
votes
3answers
95 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 ...
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....
-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 ...
-4
votes
0answers
47 views

C# SignalR and risk [closed]

Is using SignalR opening holes in security? And, also if it is heavy and load on server if lets say there are 1000 users at a time? Can anyone advise on what is good and bad approaches when using ...
0
votes
0answers
57 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
66 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 ...
0
votes
1answer
92 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<...
1
vote
3answers
105 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 ...
60
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 ...
5
votes
4answers
373 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
140 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 ...
-6
votes
0answers
66 views

Need help with parallel processing [on hold]

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 ...
1
vote
1answer
130 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,...
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 =...
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. ...
0
votes
3answers
96 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 ...
0
votes
0answers
18 views

How to provide an extension point for library that should authenticate asynchronously using WebClient?

I'm trying to design a library (nuget package) that would read data from a REST API and deserialize it to DTO objects. The API requires authentication which is usually done with Microsoft's ADAL ...
0
votes
0answers
63 views

What should I do if I am unfamiliar with my organisation's codebase? [duplicate]

I've recently started my first job as a software developer at a small startup company. I do not have a degree in a software engineering related field, although, I have very recently completed an A-...
1
vote
1answer
232 views

Refactor multiple “if” statements in C# [duplicate]

I am writing a method in C# (SharePoint Services) which is supposed to return a SharePoint list name based on three conditions (Client, Country, and Location). There are multiple clients, countries ...
2
votes
2answers
128 views

Multiple database system design

I am designing a few different systems that revolve around a core system used to manage users, groups, associations between users, group memberships, user profiles and some other things. System A ...
0
votes
1answer
118 views

Does returning an instance directly in a property create duplicate instances?

Let's say I have a class with a property that returns an array of strings. public static string[] MyStrings { get { return new string[] { "Foo", "Bar" }; } } Will this create multiple instances ...
0
votes
0answers
27 views

How to release collectiable assembly (cannot null belonging type)?

The documentation states You must release all objects that represent parts of the assembly. The ModuleBuilder that defines T keeps a reference to the TypeBuilder, and the AssemblyBuilder ...
2
votes
2answers
179 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
5answers
257 views

I feel like these constants should be in a different class?

I have a static class called RenderingUtilities that houses several useful methods and constants. Some of these constants are related to the Earth as an object such as the Earth's radius. I believe ...
1
vote
1answer
135 views

Multiple APIs v One API

Is it normal to have a bounded context spread accross multiple APIs or should there really be one API per bounded context? I am trying to understand if I can use the Scatter Gatherer pattern (https:...
1
vote
0answers
75 views

What are the “gotchas” of refactoring code that is binary serialized? [closed]

I have a few classes that I have to refactor and my particular concern is that they are marked as Serializable. I know with 100% certainty that these classes are parsed out into a file and read back ...
1
vote
2answers
103 views

Is it a good idea to use strings in a struct as values to static properties?

I'm in a discussion with a co-worker concerning the use of structs. I have a couple of structs that contain several static properties that are used throughout our website. The value of those ...
1
vote
2answers
130 views

How can I integrate Python code with c# code? [closed]

I want to integrate code python (hierarchical clustering algorithm) with code C#. (The idea of ​​the project is to divide similar people and put them into classes using the algorithm. We use language ...
2
votes
3answers
256 views

Best approach to creating a secure offline login system in C#?

I'm rather new at programming so I'm still getting a grip on things. I'm creating an offline login system in C# that will have the ability add/remove users. The computer will not be connected to the ...
45
votes
11answers
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 - ...
2
votes
4answers
136 views

Using Instance or Static Method for reusable method

I have made a lot of forms for my desktop application, some forms were using the same method which I have to copy and paste the code (not OOP). Let's say I have a method called FirstDayOfWeek() and ...
2
votes
1answer
53 views

Strategies for managing a dynamically sized pool of worker processes?

I have a problem to solve that's very much like a thread pool, and I was hoping to hear some strategies or find some resources to information on managing the size of the pool. Let's say I have the ...
0
votes
0answers
24 views

Approach for a timed events in a framework-like library - a matter of life(cycle) and death

I am working on a helper library that is supposed to send some data to a server on a specified interval, e.g. 1 minute. The idea is that the user of this library should not have to bother with ...
0
votes
1answer
83 views

Will (await method).ToList() block the thread? [closed]

I'm using a lot of async Task<IEnumerable<T>> methods and I want to stop doing this everytime to get the items as a list: var items = await AsyncMethodThatReturnsEnumerable(); var ...
5
votes
6answers
408 views

Why is it bad to use exceptions for handling this type of validation? It seems like it makes the code so much cleaner

I'm working on a .NET Core REST API and I'm writing a service class to create new user accounts. I have the following code: public async Task<UserDto> RegisterNewUserAccount(...
5
votes
2answers
295 views

Should my classes have separate constructors just for unit testing?

I like to write classes with two constructors: a primary constructor used in production code, and a default constructor just for unit tests. I do this because the the primary constructor creates other ...
3
votes
6answers
195 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 ...