Stack Exchange Network

Stack Exchange network consists of 175 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
25 views

Ranking / Generating score card based on scoresheet details

I am busy with a score keeping app. And would appreciate suggestions/ help. I will try to be brief and hopefully have explained the main gist of the app below The app basically maintains some scores. ...
0
votes
1answer
117 views

Factories to create same objects with different data sources

I have several handlers classes that implements same interface and factories to create handlers. Handlers: public class Handler1 : IHandler { private readonly IService1 _service1; private ...
1
vote
4answers
448 views

Declaring unnecessary variables for readability

I know some languages (C comes to mind) its best to declare as few variables as possible. In a language with memory management like C# is it better practice to continue with this philosophy or should ...
0
votes
1answer
54 views

Objectreference vs Equality [closed]

While coding I stumbled upon something like this (extremely simplified example): public bool Func() { Object[] array = new Object[] {false, false}; return array[0] != array[1]; } I was ...
0
votes
3answers
164 views

Designing a class whose dependancies require “starting”/initializing step

I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be ...
3
votes
1answer
154 views

Alternative to a utility class for extension methods in C#?

I understand that in OOP languages like C#, it is generally viewed as bad practice to create utility classes, and it's preferable to put methods in the classes in which they will be used. To that ...
0
votes
7answers
310 views

Good object oriented practice to use an object to build itself?

Do you think its a good OO practice to use parts of an object to build itself? Here is an example. var car = new Car { Make = BuildMake(), Model = BuildModel(), Vin = ...
-2
votes
2answers
128 views

How to handle multiple versions of binary file format

I'm writing a reader for the custom binary file format used in one game. The format has multiple versions for example: struct FileHeader { ushort version; uint fieldX; // version 1 uint ...
1
vote
0answers
46 views

Should I use gRpc in my business layer?

I'm moving from REST APIs to gRpc but having a hard time figuring out how to structure my logic. The basic layout of my solution is having a business layer/API and a few different front-ends (Windows ...
2
votes
2answers
247 views

Factory that returns multiple implementations of the same interface

A few developers and I are attempting to refactor a class that has grown too large. Currently this class is around 3K lines long. The goal of the refactor is to make the logic more maintainable. The ...
0
votes
1answer
102 views

Provide iterator while generating power set [closed]

I have written a code in C# to generate the power set of a given input list of integers. public List<List<int>> GeneratePowerSet(List<int> Set) { int setCount = Set.Count; ...
0
votes
1answer
56 views

Gerstner Wave equation from tessendorf paper, mesh penetrates itself

I have been learning to create water waves in a mesh from a paper commonly known as the Tessendorf paper. Which is quite well known. But those who don't know this is the equations it mentions in the ...
0
votes
3answers
141 views

Keeping objects in RAM vs more queries to the database

So this is my DataStructure: Project - Name - ID - Image - History - User - Comment When my application first starts it is pulling all projects with all details. obviously ...
15
votes
2answers
464 views

C# 8 non-nullable references and the Try pattern

There is a pattern in C# classes exemplified by Dictionary.TryGetValue and int.TryParse: a method that returns a boolean indicating success of an operation and an out parameter containing the actual ...
1
vote
4answers
267 views

Writing C# utility that checks on property

I have a business requirement that requires checking on a person's first name to ensure it does not have the character "1". The model: public class Person { public string FirstName { get; set;...
-4
votes
1answer
110 views

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

I'm working in TDD for my data access layer in MongoDB and I don't know what should I test? I think that I shouldn't test if the queries return what they have to return because It's a MongoDB concern....
0
votes
1answer
93 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
143 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 ...
3
votes
2answers
182 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 ...
1
vote
1answer
111 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 ...
0
votes
0answers
51 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
100 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
437 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 ...
3
votes
2answers
417 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
1answer
88 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 ...
2
votes
1answer
156 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 ...
0
votes
3answers
155 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
71 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....
0
votes
1answer
171 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
142 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
117 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 ...
63
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 ...
6
votes
4answers
440 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
144 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 ...
15
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
1answer
144 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
117 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
192 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
103 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
21 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
64 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
372 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
136 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
120 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
29 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
193 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
265 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
148 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
101 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
106 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 ...