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
2answers
176 views

Can StringBuilder be used to effectively store and manage multiple variables of data?

Using C# I want to create one or more text files to store all the data pertaining to a particular 'Thing' on the same line. I am presently leaning towards StringBuilder as per the following. sb....
2
votes
4answers
125 views

Are names like OrderCreation and UserRegistration suitable names for business logic / domain classes

We have moved to a more SRP model and found coming up with class names challenging. Previously we had a Order class that looked something like this: public class Order { public void Create() {...
3
votes
8answers
726 views

Why can't we just use variables instead of constants?

I can't see the point of constants. For example I can use the famous example of PI: PI = float(3.14) Here I get the job done without a constant. Who cares if the value never changes during the ...
2
votes
2answers
110 views

Should we add an extra class to this code sample

I have a shopping website which allows users to place orders. In my web application when the users click 'Create Order' i call an OrderService class which looks like the below: public class ...
1
vote
3answers
116 views

What should be in my business logic class

We are currently having an internal debate on how our business logic classes should be structured. At the moment we structure our business classes like this: public class OrderBL { public void ...
1
vote
1answer
163 views

What could be the better c# design for following requirement? [closed]

I am working on creating a c# design for following requirement. I am creating this for a fitness website. I have an article (as Text) and a exercise (as Image or Videos) as the base entity. Now i ...
1
vote
1answer
223 views

Why use Razor Syntax?

Was doing some reading today about Razor Syntax with MVC Framework and was wondering why would/should I use Razor? What benefit does it provide over doing the same thing in the code behind and/or ...
3
votes
1answer
68 views

Within an interface specified by a core component, should it request IReadOnlyCollection or IEnumerable?

In thinking about the principle of "be conservative in what you send and liberal in what you accept", I generally try to make my methods receive IEnumerable parameters, but emit a IReadOnlyCollection (...
3
votes
2answers
196 views

Best Practice for masking Credit Card informations in Web Api 2

In an Asp.Net Web API 2 project, We're logging every http request and response with log4Net. Some controllers have critical parameters such as "CreditCard, CVV, Month, Year" etc. This data should not ...
2
votes
2answers
236 views

Best practice for using StringBuilder

I'm writing a camera control program which uses many methods for each of the different commands. One example is: public void CameraPan(int Id, string Direction, int Speed) { StringBuilder sb = ...
1
vote
1answer
89 views

.NET Implementation Question (repository access)

I am trying to write a generic method which goes a particular DB table depending on the entity which is passed (all valid entities implement IStaticData) : IEnumerable<T> GetEnumerable<T>(...
0
votes
0answers
33 views

Should I reference both up and down a hierarchy when using Entity Framework?

Let's say I'm modelling an organizational hierarchy which consists of Divisions that contain Departments that contain Teams. So Division -> Department -> Team. While it makes sense for the Division ...
2
votes
1answer
121 views

Are nested private classes considered composition?

Background I am considering a design that includes a public API class containing many nested private classes. I am doing this for the following reasons: Why private nesting? They will have no use ...
1
vote
2answers
162 views

Is a an object Necessary or can I still use a DataTable

I'm currently working on a fund project and I have it set up so I get the holdings from my database and store in in to a DataTable to process. I've created a function where my Database results are ...
19
votes
5answers
4k views

Is it okay for a class to use its own public method?

Background I currently have a situation where I have an object that is both transmitted and received by a device. This message has several constructs, as follows: public void ReverseData() public ...
0
votes
1answer
79 views

How to call a specific element in XmlReader

You know that XmlReader reads like crazy and doesn't care about root element or anything, it just reads line by line on every element. My XML file is a student list with some of their data so ...
2
votes
2answers
160 views

Developing a new application on a restricted time [closed]

Me and my colleague are working on a new application that should replace as soon as possible an old VB6/Access 97 application made years ago.This application has a lot of problems, adjusting them in ...
2
votes
2answers
300 views

Modeling a multi-channel communication device in C#

Background We (my coworkers and I) are architecting a high level C# API to interact with a hardware device's native Windows DLL. First I will discuss the hardware-architecture, then get to the ...
1
vote
0answers
73 views

Guaranteed message sending for messages of different priority for different modules

We have created a message que system using priority messages. The idea behind this is as follows: We have a list of clients. All clients know if (and what kind of priority) messages they have ...
1
vote
0answers
58 views

Idiomatic way of uploading images using async to Sharepoint from ASP.NET 5

Another title could be 'How to make an async Repository pattern with image upload in ASP.NET 5' I'm making a site with ASP.NET 5 and it uses the CSOM (ClientContext, etc) to connect to a Sharepoint ...
3
votes
0answers
65 views

Merits of DI, Abstract Factory implementation review

I'm writing a brand new system and trying to stay true to the SOLID principles, specifically Interfacing and Dependency Injection. We are sticking closely to the Microsoft stack so we are using C# ...
5
votes
4answers
411 views

Avoiding hangs when calling a native API

Background We have a piece of programmable hardware here at work that we integrate into almost all of our systems. This piece of hardware came with a native Windows DLL (for which we do not have the ...
0
votes
3answers
196 views

What to do if I need more than one base class in C#? [closed]

Let's say I have a grid with square fields. For the fields I have an abstract Field class. This class has several subclasses, for example EmptyField or RoadField. Some of these fields can be connected ...
6
votes
4answers
274 views

How to separate public and “mostly private” code in C#? (Friend classes, PIMPL pattern, etc.)

Reminder: If you have tips, please remember to put the reason objectively, such as "having two distinct SetInt() functions in the same file violates reader expectations that they'll be overloads, and ...
2
votes
0answers
61 views

Data pipeline with fallbacks and callbacks

I'm refactoring our current design for how we download static data. It's a mess of deep class hierarchy and callback hell and I want to convert it to a more elegant straightforward design. Here are ...
1
vote
0answers
149 views

Implementing software licensing

I have an unpoliced piece of software and I must implement some control over who can install it via licensing. I already have an authentication server that implements OAuth 2.0 and OpenId that's used ...
8
votes
7answers
370 views

A property that can represent both a single date and a date range: How to properly model that?

I work in a system that can represent a "shipping estimate" in two ways: A specific date: The item is guaranteed to ship at that date A day interval: The item will be shipped "X to Y" days from ...
62
votes
11answers
6k views

Is a big boolean expression more readable than the same expression broken down into predicate methods? [closed]

What is easier to understand, a big boolean statement (quite complex), or the same statement broken down into predicate methods (lots of extra code to read)? Option 1, the big boolean expression: ...
9
votes
4answers
691 views

How to argue against this “completely public” mindset of business object class design

We're doing a lot of unit testing and refactoring of our business objects, and I seem to have very different opinions on class design than other peers. An example class that I am not a fan of: ...
2
votes
4answers
134 views

How to enforce how an interface is consumed

Imagine I have an interface: public interface MyInterface { void CallMeFirst(); void CallMeDuringApplicationLifecycle(); void CallMeOnApplicationExit(); } What is the best way of ...
9
votes
2answers
479 views

Benefits of Structured Logging vs basic logging

We're building a new app and I'd like to include structured logging. My ideal setup would be something like Serilog for our C# code, and Bunyan for our JS. These would feed into fluentd and then could ...
5
votes
4answers
206 views

Can we encourage our test team to collaborate with developers on automating tests?

I am a C# developer, and my team and I are trying to start automated functional tests. (Note that we don't want to do Unit Tests; we expect to develop tests which test one function point per test) ...
1
vote
0answers
52 views

Is there any way to take advantage of portable ViewModels for ASP.Net?

Microsoft supports portability when taking advantage of the MVVM pattern: https://msdn.microsoft.com/en-us/library/hh563947(v=vs.110).aspx This means that I can create a ViewModel that is reusable in ...
2
votes
1answer
141 views

In a polled interface, is it okay for an object representing hardware to start a task responsible for the polling?

I am a hardware/test engineer currently writing a C# application for a device that does not have any event/interrupt mechanisms. Because of this I am forced to poll the device's internal control ...
0
votes
1answer
93 views

Conditionally creating objects at runtime using Spring.NET

I have a couple classes in a project I'm working on that only register event handlers. public class EventLogger { public EventLogger(EventRaiser someObject) { someObject.EventRaised ...
0
votes
0answers
48 views

Migrating off a Silverlight application to SPA - technologies

We have pretty big Silverlight LOB application. It works great, took many years to write and it's big... Back when we made a choice (2011) JS/HTML5 was in unknown state. Today we have all kind of ...
10
votes
2answers
672 views

Why does C# allow you to make an override async?

In C#, when you override a method, it is permitted to make the override async when the original method was not. This seems like poor form. The example that brought me to this was this — I was ...
4
votes
3answers
99 views

Visibility of abstract factory's implementation's product

I'm implementing a factory like this: public interface IMyProduct { void DoSomething(); } public interface IMyFactory { IMyProduct CreateMyProduct( string aParameter ); } internal MyFactory ...
2
votes
3answers
173 views

Writing new code in async but calling sync

I am writing some new code and would like to write it using async and await, but the calling code does not currently support async. Is it right to write the new code in async and call it sync until ...
-4
votes
2answers
192 views

Automatically creating .pdf files from CSV [closed]

Ok, so I already have a small console program written (full code can be seen here) for this task. Basically, what it does, is the user grabs a CSV that is full of filenames, then chooses where to save ...
0
votes
0answers
142 views

Winform User Control on ASP?

I wrote a C# Winform User Control as follows when Executable is Run: My question is how we can use this Winform C# user control in one ASP Page. I know about WEB User Control and using in ASP but ...
3
votes
1answer
101 views

Unit testing a large project with few publicly accessible components [duplicate]

I'm asking about C#, but this probably applies to most other languages as well. Imagine I have a project with a lot of complex logic, split up into a lot of small components. Let's say that, among ...
1
vote
2answers
230 views

Would adding enums to my class make my code more compact or efficient?

I am working on a C# class library for my colleagues to use when programming industrial cameras. I'm trying to determine both the most compact and elegant method to write the class. The commands are ...
0
votes
2answers
252 views

Trust .net compiler after Microsoft updates

Microsoft releases upgrades and changes to .net, msbuild and Visual Studio quite frequently. How can I be sure the MSIL code created by msbuild or the Roslyn compiler in VS 2015 will be the same or ...
2
votes
1answer
294 views

Strategy Pattern not sufficient for my problem?

Let me sketch the situation: I have multiple users, with certain properties (2 enums) For each user I need to fetch data, for some with some basic filtering, for some extended filtering (= basic ...
1
vote
2answers
238 views

Migrating large silverlight business application to MVC

I have the task to migrate a large silverlight business application in a new living technology. I had choosed asp.net MVC and web api. As we know, silverlight uses MVVM design pattern whereas asp.net ...
3
votes
2answers
346 views

Only use a dependency injection container at the root of an application?

normally, I'll use a dependency injection container (unity) in c# like this example: class SomeClass { private readonly ILogger _logger; public SomeClass() { _logger = ...
0
votes
0answers
39 views

Graphing Objects without invoking Domain Logic

I'm unsure of how to go about implementing a certain aspect of my objects. Given a model class that represents an object, with business functionality based on various events, how can we graph the ...
1
vote
1answer
71 views

How to determine what type of derived-class object to lazy-load from an associated object

I'm modelling a system that is a combination of two distinct yet similar data repositories**: one containing patent data and one containing trademark data. There is a very large overlap in the ...
1
vote
1answer
173 views

How do I write this method to adhere to the Single Responsibility Principle?

I'm writing code that imports values from a CSV file. As part of the import process, I need to write warnings to a log (displayed on screen) when values in the CSV file are invalid. The method below ...