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

4
votes
7answers
516 views

Should I use static classes for methods that will do common tasks and would be called through out my application?

I have spent the last few hours reading up on the use of static classes and trying to figure out if I should be using them or not but still have not come to any sort of conclusion. It seems that the ...
0
votes
1answer
48 views

How to have server call a web page for data on a timer

My question is not how to call a web page in code but rather what the correct architecture for it would be. I have an MVC web app that displays certain data from our database when the user visits a ...
3
votes
1answer
59 views

Creating a service to to run logic / queries and update a table vs. running logic / queries on client refreshes

I'm not sure if this is a thing. I'm sorry about the ambiguous title--I wasn't really sure how to explain it. Basically I have a ASP.NET web page that runs two SQL queries and does some logic to ...
0
votes
1answer
92 views

Dependency injection multiple instances or only one InrequestScope

I'm trying to understand what happens with dependencies (Ninject) when a same Interface in injected in multiple classes. I am specifying InRequestScope for my bindings so as I understand there should ...
9
votes
4answers
506 views

Dependency Inversion expands the API, results in unnecessary tests

This question has bothered me for a few days, and it feels like several practices contradict each other. Example Iteration 1 public class FooDao : IFooDao { private IFooConnection fooConnection;...
8
votes
2answers
746 views

Why aren't all method virtual or why doesn't have each class at least one interface?

This is more philosophical question, which address .NET platform, but maybe it is useful also for other languages. I'm doing lot of Unit Testing and especially when I'm using third-party components I ...
1
vote
1answer
137 views

Got confused while designing Aggregates

I am designing an application, which will store sports statistics, show them in different diagrams and do few more operations on them. Allow user to do some mock drafts etc. I choose to build a ...
1
vote
2answers
199 views

Design pattern for managing three different objects

I´m looking for the best way to solve following problem: I have three lists of different objects: AppleJuice, OrangeJuice & Juice. All Juice properties exists in AppleJuice & OrangeJuice ...
2
votes
1answer
126 views

Standard way to call virtual method

So recently I was working on a project where I had a base class that provided some common functionality. It had several virtual (overridable in vb) functions. I noticed that some of these methods ...
10
votes
2answers
526 views

Is it bad to create classes whose sole purpose is to be converted to another class implicitly?

Imagine a situation where we're using a library that allows you to create Circle objects, where you can specify the radius and the center of the circle to define it. However, for some reason, it also ...
1
vote
1answer
63 views

Knowledge base UI pattern

In our database backed (C# WPF / Entity Framework) application, we want to build a system to enter, store, display and search arbitrary content linked to our main entity. The challenge here is to find ...
2
votes
1answer
185 views

Why and when would you use a .NET framework data type?

I've seen an increasing trend of people submitting code to SO that includes the use of .NET Framework data types. I understand that the .NET Framework has its own data types (like Int16, Int32, ...
1
vote
1answer
97 views

Is a PropertyChanged event handler bad if it is used for updating the database?

I have a class with several fields. public bool Active { get; set; } public List<Group> Groups { get; set; } public string FirstName { ...
3
votes
1answer
122 views

Create different classes for staffers and users?

I am building a program for a law firm. When a staffer is active (i.e. still works at the firm) he has a password to login the program; When a staffer is inactive (i.e. no longer works at the firm) ...
0
votes
2answers
71 views

How to calculate new property for old records efficiently?

Let's say we have classes something like this: public class Item1{ public Guid Id {get; set;} public string Name {get; set;} public decimal Price {get; set;} public int Quantity {get; ...
3
votes
5answers
145 views

Conditionally initializing a string list

I am writing a program that needs to be able to process data from a number of different sources. The sources output data in a variety of formats. So, depending on which source is being used, I need to ...
2
votes
2answers
296 views

Onion architecture design question

I recently started working on a new project where the team was considering use onion architecture, which I was not very familiar with, so I started reading about it. The application is a simple 3D ...
5
votes
1answer
235 views

Why does this shared buffer work?

Background The following code snippet is taken from a problem in, Visual C# 2005: How to Program, by Paul and Harvey Deitel (pp. 735). The code snippet is more or less an application for accessing ...
0
votes
0answers
35 views

Suggestions for dataloading - semi dynamic data

I have a very old Perl based system that is used for CAD drawing searches, where each drawing has many metadata fields associated with it. Currently, the 'old' system has a database schema that has ...
2
votes
0answers
204 views

Dictionary of dictionaries design in C#

My question: is there a canonical way of creating a dictionary of dictionaries and providing an outer/inner key pair? Is there a NugetPackage out there with an implementation? In my code, I have now ...
11
votes
5answers
403 views

Is indiscriminately catching exceptions (Pokemon exception handling) ever acceptable? [duplicate]

Normally, I don't anticipate exceptions and if I get them, its something that I can't fix in my code - bad user input or connectivity issues with the database. But errors do occur so at the very ...
5
votes
4answers
222 views

Does anyone have a good DI registration pattern?

I've done this so many times but I never end up liking how my code turns out. I'm asking if anyone else has the same problems and can offer solutions or conventions that they've used to make cleaner ...
-4
votes
2answers
154 views

Referencing a C++ DLL from within a C# ASP.NET project using Visual Studio Community 2015 [closed]

This question might be a little odd, but is there any specific way to import a C++ reference into an ASP.NET C# project? The problem I am having is that VS is giving me the following error: ...
-4
votes
2answers
179 views

OOP project design

here is the UML class diagram subscribe method is used to add a herbivore object to the plant's watchers. when a plant is told to notify, itloops through all of the herbivore object in its watchers ...
0
votes
1answer
174 views

Is there an easier way to do this with Lazy<T>?

I was trying to find a concrete example online but I couldn't find one that also used one of the class' other attributes. So, can this be done more succinctly with a Lazy<T> object? public ...
2
votes
2answers
94 views

What is the best approach to update a database field when a corresponding class property changes?

I have a class with several fields. public readonly byte Id; public bool Active { get; set; } public List<Group> Groups { get; set; } public ...
1
vote
1answer
145 views

Using ninject in a class library

Looking for some help getting my head around ninject and DI. Using the simple examples I've found online everything works nicely but trying to do something more complex is causing headaches. I have ...
0
votes
3answers
169 views

Is data duplication bad in programming (in contrast to database designing)?

I have three classes: User, Conversation and Message: Message properties: User sender; // Some more Conversation properties: List<Message> messages; List<User> participants; // Some ...
1
vote
1answer
81 views

Asynchronous client-server implementation

The mission: Implement a program that will listen to multiple client requests asynchronously (on TCP) and transfer them to a server (also on TCP) to which only one connection is allowed. The program ...
2
votes
2answers
132 views

How should I represent mutable boolean state?

When I have some object with boolean state that can be changed (like a checkbox's checkedness), there are several ways I can expose it. Getter property, Setter method bool IsChecked { get { ... } } ...
5
votes
2answers
138 views

Recreating complex aggregates from a persistance source

I'm building a web application with C#, and I have an aggregate root which has several entities and value objects. Then I have a repository object which persists the aggregate to the database (I'm ...
7
votes
4answers
235 views

Code design: Duplicate code or good implementation

I'm working on application in C#, where I need to serialize and deserialize some classes into/from XML. This operations will be implemented in Class Library. I chose XMLSerialization class to ...
2
votes
2answers
149 views

C#/VB struct – how to avoid case with zero default values, which is considered invalid for given structure?

How to implement some constrained .NET struct/structure (let's say LimitedString), where its state with default values (set by CLR to technical defaults, i.e. nulls, zeros, etc.) should be prohibited ...
2
votes
4answers
155 views

Unit Test for Void which copies data from one location to another

Still learning and getting my head around Unit Testing, (also trying to get into TDD, though I appreciate it isn't the same thing) and in many ways it is changing/improving my code. But I come across ...
0
votes
2answers
249 views

Don't auto-implemented properties violate encapsulation?

In C#, when a field getting or setting requires logic, we use properties. For example: private int _age; public int Age { get { Console.Writeline("Club member is {0} years old", _age);...
1
vote
4answers
271 views

How to mark/track features in code?

After some time in every project sooner or later you will need to find a feature in it a fix it or extend it so I was wondering if there is already a system or a convention for marking those features ...
4
votes
1answer
133 views

Have the unit test “using” the project, or just have same namespace?

Background I am working on a project with C# .NET, and I've just added a new unit test project to my solution in Visual Studio. The way that I always have been doing this is: Create a new unit test ...
7
votes
2answers
400 views

Is there any reason to use a Func over a method?

I recently just started looking at Func in C#, and as far as I can tell, they pretty much are the same as methods, which is fair enough. However, I was wondering if there is any point in using them, ...
7
votes
3answers
267 views

Using Interfaces for Loosely Coupled Code

Background I have a project that depends on the usage of a certain type of hardware device, while it doesn't really matter who makes that hardware device as long as it does what I need it to do. With ...
4
votes
1answer
247 views

Is there a term used for the collection of a key and value in a C# dictionary?

simple question, I want to know if there's a word/term used to describe the collection/pair of a key and value in a C# Dictionary.
0
votes
1answer
80 views

One time use token Mobile / Desktop linking. How to?

I want to know if there's a way or known way to implement this: Lets say I have: a C# WinForms program a Javascript Mobile Application (Android / iOS) What I want to do is: for my C# ...
3
votes
2answers
163 views

Correct way for storing data for runtime use in stand-alone applications?

I am working on a project that involves a "team builder" type application, if you will using C#. For the sake of simplicity, let us say it involves the user creating a "Team." There are three teams ...
4
votes
2answers
280 views

Why is an abstract class forced to define all functions of an inherited interface?

Why does c# compiler force an abstract class to define (as opposed to implement) all the methods of the inherited interface ? why does it not mark unimplemented methods of an inherited interface as ...
4
votes
2answers
112 views

Applying composition over inheritance to Vehicle classes

I have a car maintenance garage program that has an abstract Vehicle class that has several derived classes like Car MotorCycle, etc. Each of those derived vehicles in turn is either a fuel or an ...
1
vote
2answers
44 views

Printed Page layout application with images in C#

I'm working on an application to help create printed-page layouts (to be then fed into a custom script for InDesign). I'm facing a problem regarding placing images on a page. Either a single image ...
4
votes
2answers
193 views

Name for a Chainable ForEach [closed]

Linq has a method Select, which takes a Func<TIn, TOut> and maps it over an iterable. I'm trying to come up with a good name for a method that takes an Action <TIn>, transforms it to ...
4
votes
3answers
101 views

How can you separate a monolith into domain-driven libraries without duplicating interfaces and still keep dependencies simple?

I'm working on a project with web services, and I've been structuring things where: The web service contains the business logic layer A library which handles the data access layer I've recently ...
1
vote
1answer
109 views

Should I actually be using encapsulation here?

Problem Statement I am going to write a library to control a whole bunch of relays, and I am just trying to think conceptually right now. Here are my design constraints: We have an exact number of ...
7
votes
1answer
146 views

What kind of members should be used in a GetHashCode() implementation

We're building some Roslyn analyzers concerning GetHashCode(), including an analyzer that implements it for you in a given class. While researching the subject we've found that there are many ...
1
vote
1answer
103 views

Standalone library for error logging?

Background Here is how I currently log any exceptions that occur in my code: Pass each object instance the path to a file where I want all of the logging to happen. Each of the objects have their ...