C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform
1
vote
0answers
23 views
Update Immutable object on a Repository
I'm working on a large critical Framework, so I'm trying to find a convenient solution for our clients but not error prone...
Users create tasks and they are chained or run in parallel. A task can be ...
4
votes
1answer
31 views
Stubbing Properties with private setters for tests
We have the object
public class MyObject{
protected MyObject(){}
public string Property1 {get;private set;}
public string Property2 {get;private set;}
public string Property3 ...
-3
votes
0answers
49 views
How to implement the longest common subsequences in C#
I have read this paper which explains an algorithm for finding the longest common subsequences. I have problem with coding of creating matchlist of Algorithm 2 on page 352. Well, to be exact,
it ...
2
votes
1answer
69 views
Passing MVVM objects to other classes
So I'm using C# WPF and binding to a Model View to display states. The data that needs to be displayed is spread across a couple different classes. For instance I have a class that reads out digital ...
1
vote
1answer
83 views
HTTP Async/Await Task: avoid flooding server with requests?
I have a scenario where I have a Windows Store Application, there is a page with a search functionality, the user types names in a textbox and the app searches for names similar to the typed text.
...
12
votes
2answers
1k views
Filtering foreach loops with a where condition vs continue guard clauses
I've seen some programmers use this:
foreach (var item in items)
{
if (item.Field != null)
continue;
if (item.State != ItemStates.Deleted)
continue;
// code
}
instead ...
-1
votes
0answers
132 views
Do we have to avoid the Get and Set Methods? [duplicate]
I'm trying to understand more about Interfaces (Why should I use them) and in the road I stumble across a couple of good blogs regarding Design.
Of what I read, having Interfaces in your code is ...
-4
votes
0answers
31 views
How to process / monitor directory and display contents in Parallel in C#.NET? [on hold]
I have an interesting scenario, where I don't know which approach do I need to follow.
My application should check input directory after each defined frequency (i.e say after 5 sec or 10 sec) and ...
2
votes
1answer
142 views
Data Layer vs Business Layer
I think I'm in the minority on this but would be curious to see other perspectives.
A lot of times I see people talk about the Data Layer like having functions like UpdateCustomer() or Summarize(). I ...
1
vote
0answers
71 views
Having a globally static cached list without breaking encapsulation?
I have a couple wrappers around third party APIs that allow me to retrieve information from certain web services. Querying these services can be rather time intensive, so in my older version of my ...
1
vote
1answer
73 views
Setting up my inheritance model?
I'm working on refactoring a synchronization web app that our company uses. Currently it's merely a set of controllers that fire up a set of helpers that go through a long chain of if-else type ...
1
vote
1answer
71 views
How to handle multiple “valid after {date}” in a performant way
We work on an Application which displays a duty roster and also some other DateTime related things.
So my Database is full of Relations like in this small Example:
This results in big ...
-1
votes
1answer
31 views
Best way to control serialisation of posted form data [closed]
I'm working on an ASP.NET MVC project. I have a form that is strongly typed. Is it considered good practice to add serialisation attributes to the same view model to control how the data is serialized ...
0
votes
2answers
170 views
Should conditional logic be always coded via type system where possible?
I have a choice.
Option 1:
public class Sample
{
bool IsRelevant { get; set; }
}
Option 2:
public class Sample
{
}
public class RelevantSample : Sample
{
}
Is there a clear well-known rule ...
-2
votes
0answers
26 views
External Graphic Designer modify .proj file [closed]
This is similar to this question, in that my situation is a remote customer and remote graphic designer.
The web app is MVC 4 w/ Razor. The graphic designer has been creating mock html files and ...
2
votes
5answers
553 views
Architect in our company is against DTO [closed]
I have this easy DTO (Data Transfer Object):
public class SoonestOffersModel
{
public Offer Offer { get; set; }
public DateTime Date { get; set; }
}
Offer is entity.
Our architect is ...
3
votes
0answers
299 views
Writing a Compiler - .reloc section of the COFF
I'm looking for a little bit of direction in writing a compiler. I've written in Common Intermediate Language, C#, and various other .NET languages; I've written my own Metadata Parser and now I'm ...
2
votes
1answer
77 views
Minimizing lock time (multithreaded app)
I have a web application written in C# which uses external dll written in C++. Communication between clients (web browsers) and a web application is done using SignalR. For communication between web ...
2
votes
2answers
243 views
Generics vs common interface?
I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't.
The second answer to this question made me to ask for ...
3
votes
2answers
145 views
How to handle Data Fetching for Circular Object References in OOP Domain Models
I'm trying to put together some basic models in OOP (C#), and apparently I've got the wrong idea.
If I have a Workman's Comp case, it is applied to a Patient. It also has one or more PatientVisits ...
12
votes
5answers
736 views
How to avoid violating the SRP in a class to manage caching?
Note: The code sample is written in c#, but that shouldn't matter. I've put c# as a tag because I can't find a more appropiate one. This is about the code structure.
I'm reading Clean Code and trying ...
-3
votes
2answers
73 views
For loop valid usage? [closed]
I've just been experimenting with a console c# application and thought of a different way to do for loops to the standard int i = 0; i < x; i++ method.
I found that using this (see below), is ...
-1
votes
1answer
58 views
What is better to design or discover interface [closed]
Let's say you have some issue to develop. And as recommended practice it is good idea to use interfaces ( I don't mean GUI, I mean interface or abstract class ). And you can apply two ( I'm pretty ...
7
votes
5answers
402 views
Refactoring three very similar classes using inheritance?
I'm currently working on refactoring the code-base for one of our services. I'm been going through reviewing everything, and I feel it's a bit scattered, and could probably adhere to OOP principles ...
1
vote
2answers
88 views
How to mitigate complexity of fallbacks introduced to automatically retry upon failure?
So this may come off a bit broad and generalized, but after spending some time working around under developers, I've come to notice many different methods and design patterns. However, one big thing ...
3
votes
3answers
103 views
Streams: what has happened after instantiation but before reading?
I'm trying to grok streams - my world is C# but I suspect the principles are general.
I understand the general principle of reading/writing bytes from/to a store. However, what I don't understand, ...
0
votes
0answers
20 views
From which namespace class HttpClient should be used in UWP applications? [migrated]
Hey I am developing side project for Universal Windows Platform that will target Windows 10 Mobile phones (mainly). In this app I often ask web service to get and post data with use of HttpClient ...
3
votes
3answers
178 views
Do I need a parent class if I'm using an interface?
I'm starting work a new personal project to send out emails using different email services (like mailchimp, for example). I just started coding and I have a base class called Email:
public class ...
0
votes
1answer
57 views
Design patter for a dynamic filter builder
Say that I have an abstract base class Shape and its derived classes Triangle, Square, etc.
Currently I have the following (simplified) structure to fetch a list of Shapes and filter them (mostly ...
0
votes
1answer
48 views
Permuting and combining the values based on the key
I am trying to generate a table which would show all possible combinations based on the key. To make it more clear lets say I have a kind of Key, Value pair set(Its mentioned kind of because there are ...
0
votes
1answer
73 views
Data stored in two separate tables, how to select the right table
I have two Tables T1 and T2 in which, where in T1 contains column name 'Year' which saves year information and T2 contains column name as 'P_year' which saves year information.
In the Table T1, I ...
2
votes
2answers
54 views
How can a method handle validation and entity creation without output parameters?
I have 3 simple classes. A Reference, a Parent, and a Child. The Child knows the Reference and Parent instances it's associated with. Here they are, initialization and other data/methods omitted:
...
2
votes
2answers
82 views
Is it appropriate to use id-s in MongoDb subdocuments?
I'm currently familiarizing myself with NoSQL by building a simple web application using MongoDb with the official C# driver. If i have understood the NoSQL concept correctly, then only the aggregate ...
1
vote
2answers
175 views
The granularity level to repeat code: should downloading, unzipping etc. be handled by separate classes?
I make extensive use of DI, but I wonder, where is the 'granurality' limit, when some set of functionality should be separated to a class - lets take an example:
public class DownloadManager : ...
2
votes
3answers
203 views
A better way than O(n^2) for traversing a dictionary of dictionaries.
I have a Dictionary of Dictionaries that I need to traverse to find two records with various matching parameters. I have two foreach loops to do this which is O(n^2). I am looking for inspiration to ...
2
votes
2answers
198 views
Can I wrap a collection with a static class and still call it repository pattern?
I couldn't find a single example about repository pattern using something else then a database.
My goal is to have a global static repository that stores some objects in memory. I don't want it to ...
1
vote
3answers
137 views
How should you look at unit testing protected members used by the abstract base class?
I have the following class(es) that I want to write unit tests for:
public abstract class BaseClass
{
public bool IsFooBar(Order order)
{
return order.IsNew && ...
4
votes
2answers
137 views
Passing a list of choices with different arguments for each choice
I am writing a card game, in which I separated the "Core Logic" of the game from the UI. Communication with the player from the core logic part is done via callbacks which the UI implements and ...
1
vote
1answer
70 views
Unit test structure focused on responsibilities
I'm not going to ask what is the best unit test structure or how to do it again. There are already enough questions about it. Instead I'd like you to tell me what else I could consider in the ...
1
vote
1answer
124 views
Best practice to extend Model in View Model
I'm facing an issue where I have a Model which I want to implement a GUI for. As I'm exploring MVVM and WPF I will of course use a View Model between the View and Model. I will also have a need to add ...
3
votes
3answers
124 views
Is it considered a bad coding practice to write methods/properties that support (only) testing? [duplicate]
When I write (unit) tests I always try to avoid for example microsoft fakes because then the edit&continue feature no longer works. However this often requires refactoring... and sometimes methods ...
0
votes
0answers
30 views
Reflection of IPAdress.HostToNetworkOrder changes type UInt32 to Int64 [migrated]
Background:
I am writing a client in c# to communicate with a server written in C according to a protocol. The protocol can be thought of as a chain of packages which in turn contain some fields. ...
-2
votes
1answer
139 views
C# how separate string letter by letter, apply shift, then concatenate [closed]
I need to make a C# program with the following task:
Break string into letters
Match each letter with an array: A=1, B=2...
Apply a variable shift to each letter: letter=letter+shift.
Here is my ...
0
votes
1answer
57 views
Multiple variable assignment vs HashTable lookup
I'm writing a CUIT ( Coded UI Test ) and I'm replacing variables with data fetched from a csv.
Example:
this.UIMap.IDBParams.UITboxFsEditText = TestContext.DataRow["num_fs"].ToString();
...
2
votes
1answer
75 views
Code for Inherit design
I want to write application that takes Wireshark File and read all the packets inside this file.
So i want to able to support several formats.
Until now i can handle Libpcap, Pcapng and TcpDump.
So i ...
1
vote
0answers
103 views
Where to store formulas and formula “constants”?
I want to implement a database driven payroll system using CSharp. I already did it once, but the implementation sucks so I want to do it again and do it right.
My first thought is to create a static ...
0
votes
1answer
106 views
Switch complex WinForms app to WPF MVVM
This question is connected with my older question C# Application GUI design dependent on configuration.
I have built quite big WinForms application working in industry for a few years. It ...
3
votes
3answers
151 views
Best practices regarding type mapping and extension methods
I want to ask some questions about best practices regarding mapping types and using extension methods in C#. I know this topic has been discussed multiple times over past few years, but I've read a ...
2
votes
2answers
109 views
Should we include Nuget PACKAGE folder in version control?
I would like to know
In C# or VB.NET project should we include the PACKAGE folder (nugget package folder that is created to the root of my project that contain the nupkg files and other content) to ...
1
vote
2answers
130 views
How are abstract database interfaces written to support multiple database types?
How does one begin to design an abstract class in their larger application that can interface with several types of databases, such as MySQL, SQLLite, MSSQL, etc?
What is this design pattern called ...