C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

learn more… | top users | synonyms

0
votes
1answer
67 views

Access rights through database table

I made a login system with access rights (ASP.NET WebForm) and I store the info's in a database table. I don't use the built in feature of asp.net like Forms authentication and webconfig. My question ...
5
votes
4answers
402 views

Why use plus equals += for event registration?

In C#, you register an event like: window.onClick += myHandler; But why use this instead of a "register" method that takes your handler and registers it. E.g.: window.registerOnClick(myHandler); ...
5
votes
1answer
154 views

Call base inside overriden method

I know there are questions about calling the base method inside an overridden method such as this. But what if an overridden method only calls the base class? Is this bad/good deign? It just seems ...
6
votes
2answers
248 views

Does a C# event have to have an object type as its first parameter?

I have a TCPClient class. It has several ClientEvents. Originally it followed the standard pattern public delegate void ClientEvent(object sender, ClientEventArgs e); Only TCPCLient uses this event. ...
0
votes
1answer
41 views

Include exceptions in activity diagrams? [closed]

Should I include exceptions, like a TimeOutException or just general Exceptions, to a activity diagram? For example: A activity diagram describing a client-server connection. Several exceptions can ...
0
votes
0answers
90 views

Generic Type Parameters where one is itself Generic with a Type Parameter of the Other

I have a couple of classes with the following pattern that I am uncomfortable with. Is this the only way to do this, or are their other design patterns that would be more reliable. public class ...
2
votes
2answers
144 views

Clarification on dispose method

If I wrap in a class an object that has the dispose method I'll need to implement the dispose method in the class too? For example I have a class which wraps an instance of SQLiteConnection, should I ...
0
votes
4answers
375 views

In C#, what is the benefit of assigning a class variable to an interface variable before calling any methods?

Where I work we develop in C# .NET and I was looking a code that they have made (my job is to optimize it) but I saw something in particular: Assuming that InterfaceDHO is an interface and ClassDHO ...
4
votes
3answers
175 views

Alternatives to Singletons for caching lists of data?

In my project, I have an abstract Cache class that allows me to populate a series of lists that globally persist throughout my application. These cache objects are thread-safe and can be manipulated ...
5
votes
3answers
113 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
1answer
130 views

Passing MVVM objects to other classes [closed]

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
152 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. ...
14
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 ...
2
votes
2answers
246 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
84 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
88 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
80 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 ...
-2
votes
1answer
58 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 ...
2
votes
3answers
316 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
5answers
599 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
328 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 ...
3
votes
1answer
108 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 ...
3
votes
3answers
363 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
165 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
766 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 ...
-2
votes
1answer
69 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
441 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
92 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
118 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, ...
3
votes
3answers
189 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
82 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 ...
-1
votes
2answers
75 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
88 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
64 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
136 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
183 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
213 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
219 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
154 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 && ...
5
votes
2answers
158 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
75 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
203 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 ...
2
votes
3answers
141 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
1answer
64 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
123 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
185 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
242 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
137 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
213 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 ...