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
0
votes
0answers
26 views

Where's the best place to put formatting logic

I have an MVC application where the data entity structures are in the Model layer. On top of that there is Business layer that sits between the Controllers and Models. There are various places in the ...
0
votes
3answers
49 views

Using (Collections of) Tuples as Class Properties in a Public API

I have a parameter object that represents a single match in a competition, and one of its properties needs to contain that match's game scores for both players. For example, in a match determined by a ...
5
votes
4answers
4k views

Which is preferred: subclass double or create extension methods to test (relative) equality due to floating point differences?

I am writing numerical calculation software using .NET C#, which needs to be blazingly fast. There is a lot of fractional math. So using decimal type is pretty much out of the question, given its poor ...
0
votes
0answers
36 views

Inconsistent data between different viewmodels

Im building mainly WPF applications. I noticed a "problem" with inconsistent data. Usually I have a ViewModel, the VM has a load method, which gets data from the database, the user can edit ...
0
votes
4answers
179 views

Is it an issue to have multiple almost identical interfaces?

Is it an issue to have multiple almost identical interfaces? In our company we have 9 identical interfaces for 9 document types, like: Book, Contract, Person, etc. interface IBookInner { Book ...
0
votes
1answer
75 views

Combining synchronous and asynchronous commands when using the command pattern

Let's say I'm building a simple console app which has three commands: Create category. Download recipe from API to category. Display all recipes in a category. Assuming the app will grow, I use the ...
1
vote
1answer
32 views

Communication mechanism among windows or pages WPF

I work with C# and WPF and not using MVVM approach. One of the important part of applications is communication among Windows Pages and UserControls. In MVVM they do it behind the scenes and let you ...
1
vote
2answers
84 views

In C#, is it reasonable to use a #region when I need several members to implement a common interface?

I know that lots of people hate #regions in C#. IMO there is at least one legitimate use of them: Sometimes I have a class which, in addition to its core functionality, needs to implement a commonly ...
-3
votes
1answer
67 views

What is the best way to notify the developer (myself) of errors during production?

I'm starting to write production software (just for myself, not for a company with a pre-set mode of operations for this). I want to find a way to send a message from my users to me (the developer) ...
-1
votes
1answer
28 views

MVVMCross multiple ViewModels and Views per Window

I may not being fully understanding MVVM or how MVVMCross works, but my understanding of views is that they are components of a window rather than the window itself. When you start up MVVMCross in C# ...
-2
votes
3answers
253 views

How to avoid giant main function because of dependency injection

I try to use dependency injection as often as I can but every time I end up with the same problem : I always have a giant main function. If I use it without any framework and send the classes in the ...
-3
votes
2answers
51 views

What pattern for different data descriptions

We need to call a webservice which registers a shipment with either UPS or TNT. You fill in some details, call the function to register and pass json for details. Pretty basic stuff. Shipment shipment ...
1
vote
3answers
98 views

DDD - How to validate an entity is valid when said entity is a different domain which i dont have access to

I am wondering how I would validate some actions in my domain when a parameter of an action needs to be validated, but that parameter's entity is actually in a different domain so I can't retrieve it. ...
-4
votes
1answer
47 views

Changing databases in general repository methods when using Dapper [closed]

I'm developing a multi-database application. There is one admin database and many customer databases which are identical in structure. I also have a generic RepositoryBase which looks like the ...
1
vote
2answers
79 views

How to write a container that deals with a supertype but also the subtypes?

My situation is that i am trying to model an inventory system in a game, In the game there are items that can be placed and retrieved from the players inventory. For example; player inserts a sword ...
0
votes
1answer
61 views

Mark exception as handled, rethrow, display

Inside my business logic, I have something like a pipeline with multiple actions. Each action wrapped into try/catch and can handle exceptions by himself (logging, saving state for retry ex). And I ...
2
votes
2answers
84 views

Is it right way to make Window to Singleton and call Visibility and Shutdown() methods directly in WPF?

There is a parent window that is the basis of the program, and there are several sub windows under it. Editor is one of the sub window and I'm making it. The code is as follows: // This is Code-Behind ...
-4
votes
0answers
20 views

Search engine for Document management system with RBAC

I created Document management system (C#,asp.net, sql server 2012) -1- DB sql server. -2- RBAC user permission.(Read, Write, edit, Search) for each Document and folder -3- create index for each ...
-1
votes
1answer
107 views

Doing work when passing constructor arguments

This is very closely linked to the question Legitimate "real work" in a constructor? but not quite the same. I am interested in having feedback on whether this is acceptable or has any risks....
-2
votes
0answers
58 views

Microservices : How to handle queries that don't fit the mold?

I am currently removing all my sql queries called within my winform project. I've created services to map my business model objects. I need now to remove direct sql queries that join several tables, ...
-5
votes
0answers
32 views

How to implement Http proxy in C# (.Net core ) to record Socket.IO traffic from a web site running in Chrome

I need to record Socket.IO data from a website running in a chrome browser, because I need to do further analysis on the data. I think some kind of web proxy should be used. Ideally I would like a ...
2
votes
1answer
39 views

Best approach to connect master and child table while insert data in tables

I need advice what is best approach to connect data between master and child table. I have console application written in C# which scrape data from web, process data and insert them in table. Master ...
1
vote
4answers
194 views

Should Unit Tests share the Same Data set?

We are writing application service tests across our Data Service Class. Currently writing tests liking add Product, remove Product, check for inventory after sale, etc. They are all using the same ...
81
votes
12answers
23k views

What is the utility and advantage of getters & setters especially when they are merely used to read and assign values to properties of an object? [closed]

I’m still really new to learning to program. Just learning the syntax for a few programming languages at the moment. The courses I viewed for C# and Java touched only very briefly on getters & ...
-2
votes
1answer
117 views

Would structs be better than classes in this scenario?

I've recently been developing a networking application layer (or at least attempting to) for my game I've been working on. I think I've got a decent basic idea for the system now, but there is ...
0
votes
1answer
72 views

Tips on getting started writing a Roslyn analyzer for this case

Consider the following classes... public abstract class Option<T> { public T Value { get; protected set; } } public sealed class Some<T> : Option<T> { public Some(T value) ...
0
votes
1answer
35 views

Supplying application state to a resuming Hangfire background job

If this is better suited for StackOverflow let me know and I'll head over there... I think it belongs here though. I'm writing an ASP.NET Core REST API that returns 201s and 202s after kicking off ...
0
votes
0answers
70 views

With C#, in what way would it be problematic to have hundreds of classes derived from one abstract class? [duplicate]

With C#, I am defining the physical structure and behavior of a robot. For the physical structure: I wrote an abstract "Unit" class. Other classes such as "Factory" or "Arm&...
-4
votes
1answer
35 views

Small scale document management system architecture / patterns

Im usually working with line of business desktop software. Mostly based on a single database. Pretty often one of the requirements is to keep track of some files. Or the only way to implement a ...
-3
votes
1answer
149 views

What is advantage of parameter-less methods?

MVP best practices recommend using parameter-less methods when view and presenter communicate. Even if using events, it is recommended not to use event parameters. It is recommended to change class ...
0
votes
1answer
58 views

design pattern for ensuring that a container object has at most one instance of an editor

My application (VSTO/C#) handles excel files editing some cells and inserting some rows. My problem is more generlaized than this though, and is about defensive coding the class that acts as edtior. ...
1
vote
2answers
76 views

What is the proper way to handle with View and ViewModel in WPF?

Currently, I'm making an Editor with MVVM pattern in WPF. Editor simply take an instance of a specific type as a reference and modifies it. The following code is the expected usage when editor ...
-2
votes
2answers
78 views

How to Mock NamedPipeClientStream

I created a class called MpvController to handle communication protocols over a .NET NamedPipeClientStream. Now, I need to test this controller. I have a second class named MpvControllerFactory that ...
0
votes
2answers
155 views

What is the correct way to unit test methods that mix dependencies and business logic?

I'm struggling to come to a consensus on the right approach that can be used somewhat consistently to balance integration and unit testing. Take the following method, that is extremely common to find ...
1
vote
1answer
88 views

Adding item (or incrementing count) to ListView, with the MVP pattern in WinForms

Description A WinForms application with the following as part of a form: When the "Add" button is clicked, a new entry is added to the ListView, with data from the TextBoxes and ...
2
votes
1answer
71 views

Does passing a view model down to a properties violate MVVM or OOP?

I'm new to MVVM but experienced in OOP. I have an easy solution to my problem, but I'm not sure if it violates MVVM or OOP or if it is a good practice. I have a set of ViewModel classes in my WPF ...
0
votes
5answers
272 views

How to force consumption of an object once it is created?

Use case: I need to create serial numbers that are accountable for, so serial number objects, once created must have a destination: either they are used (they get a code) or they are discarded. For ...
5
votes
2answers
195 views

When to consider reference tables?

When thinking of an application. Let us say an applications user details. Let us say the application allows a user to easily edit their profile. For a field like gender, which in most cases will be ...
3
votes
3answers
234 views

Why are Service Locator frameworks often called Dependency Injection Containers?

First, here's how I understand these two concepts: Service Locators are not Dependency Injection. Both Service Locators and Dependency Injection are applications of Inversion of Control. This is the ...
-2
votes
1answer
101 views

How to do achieve parallelism in a console application

I have a .net web application, let's say A and a .net console application, let's say B.In A, I have a queue with multiple jobs to be done by B.Once I select the jobs from A, a queue gets created. Each ...
5
votes
6answers
390 views

How to modify object properties?

I've recently read a great article about unit testing. There was an example of a bad method which is not well designed. It looks like this public static string GetTimeOfDay() { DateTime time = ...
0
votes
2answers
207 views

C#: Use Double Await Cause Issues?

We have Application service Method, which extracts data from SQL database using Entity Framework Core . Its Async method along with the Async Controller. Service: public async Task<IEnumerable<...
3
votes
2answers
215 views

What is the rationale for making certain methods for data types static?

In C#, for instance, there are static methods for telling if a string is null or empty, finding an element in an array, clearing an array, etc. However there's an instance method for replacing ...
-1
votes
1answer
74 views

Good practices for frontend-backend communication

What are some good practices for handling communication between a frontend and a backend? From what I know in order to keep things loosely coupled you shouldn't just have your frontend have a ...
2
votes
4answers
242 views

Altering the state of a composed class by its composing classes. Is there any rule or principle for not doing so?

In other words, is it good to define the method that removes an element in a collection inside the class representing the element, considering a composition relationship? Something like: listElement....
0
votes
3answers
78 views

When to set constants during DI setup and when expect them on the fly as parameters?

Let's assume you have a project (e.g. .NET Core) using dependency injection. A database repository relies on a database connection string. public abstract class BaseRepository { // use this when ...
6
votes
3answers
215 views

What are the benefits of multiple projects over namespaces in a solution?

I have been tasked to set up a guide for a microservice solution structure and find myself reflecting on why exactly I do things the way I do them. I am struggling to find an answer to the question ...
1
vote
2answers
115 views

Is this approach with JWT tokens wrong?

I have .NET Core WebApi application with JWT token for authorization. I also have roles and permissions. To make it more flexible for end user, I decided to make permissions like this: [Authorize(...
0
votes
1answer
152 views

Is it ok to Inject a whole object instead of only the dependencies

I'm working with the Dependency Injection Pattern in Unity3D (an engine which uses MonoBehavior, a class that doesn't have a constructor, as the base class for all of its game components), and I ended ...
4
votes
5answers
228 views

How to fix a pair of tightly coupled classes that store references to each other?

I have the following situation: class User { public Thing curThing; } //each thing can only belong to one user at a time //And vice versa class Thing { ...

1
2 3 4 5
90