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

3
votes
1answer
100 views

How do I Balance Multiple Service Contracts with Duplicate Structures

My current task requires me to use a set of web service calls to a 3rd party vendor in order to retrieve and update information. The objects used in these calls - namely the response from a get and ...
18
votes
6answers
24k views

Advantages and disadvantages to using XAML/C# or HTML5/JavaScipt for Metro apps? [closed]

I was just wondering if there are any major advantages or disadvantages to using either XAML/C# or HTML5/JavaScript for Metro Apps.
2
votes
2answers
152 views

What's the best way to create a two-level library, containing a class with different levels of abilities?

I would like to create a library consisting of two layers, lets call them A and B. There should be a class "Sample" in layer A. Layer B also knows about class "Sample" and enlarges it by some methods. ...
4
votes
2answers
98 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 ...
2
votes
2answers
1k views

Tree View Children condition indicator on topmost un-expanded parent

I am using a tree view in c# and i am creating custom icons for the nodes. Let say this is my hierarchy with a node that satisfies a certain condition: Root1 |_Ax |_Bx1 |_Bx2 |_Cx1 ...
0
votes
3answers
154 views

Using nested private class to hold data from csv file

I have a class that only has one method. This method has to read csv file, do some work concerning internal logic (check if item already exists, do some transformations, etc.) and finally write all ...
2
votes
1answer
29 views

Appropriate Exception Type for Connecting to a Device via COM port

I'm working on creating a C# wrapper library around a native C library that allows me to directly communicate with a particular piece of hardware over a serial (COM) port. Of course, the C library ...
3
votes
3answers
87 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
102 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 ...
1
vote
1answer
903 views

How to test model binding within an MVC controller when Bind attribute with Include list is used?

Auto-generated action methods in MVC5 make use of the BindAttribute with an Include list that contains the field names in a string literal. Example: // POST: MyTable/Edit/5 // To protect from ...
13
votes
4answers
4k views

Am I wrong in thinking that needing something like AutoMapper is an indication of poor design?

Automapper is an "object-object mapper" for .Net, which means copying objects from a class into another class that represents the same thing. Why is this ever useful? Is the duplication of classes ...
1
vote
1answer
411 views

Folder structure or database structure for creating/editing 'files'?

As a hobby experiment I am creating a on-line tool for creating web sites with the ability to create custom HTML and CSS using a template engine for safe-use of functionality. Now I am in the ...
1
vote
2answers
1k views

How I could update a DB table using a POCO class bound in a DataGridView

I try to explain better using an example: I create the class Product with attibutes like that: private string _ProductCode = ""; [DisplayName("ProductCode")] public String ProductCode { get { ...
3
votes
2answers
165 views

Using “partial” type to shorten main class file

Is it a normal practice, or a sign of a bad design? For example I have a function that loads prefabs in a main logic class nearing 200 lines, and I can either move it out into a separate file ...
7
votes
1answer
137 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
84 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 ...
1
vote
2answers
592 views

How can I set a time limit for a game?

I am learning the multi-threading and timer in C# now. But it seems I can't find a good solution. For example, I would like to see how many addition problems that I can solve within 1 min. I would ...
1
vote
2answers
107 views

Return object or dynamic from a method

I have created string to linq query library for internal company needs. We will use this library for querying over REST mainly, but it could be used in a lot of other different situations. The gist ...
8
votes
3answers
6k views

Looking for a distributed locking pattern

I need to come up with a custom recursive object locking mechanism\pattern for a distributed system in C#. Essentially, I have a multi-node system. Each node has exclusive write permissions over ...
1
vote
1answer
255 views

Clarification about Event Producer in StreamInsight

I need a small clarification about StreamInsight, I know by doc's that StreamInsight can handle multiple concurrent Events. But will the event producer be a separate function, for ex: I need to watch ...
6
votes
2answers
421 views

How to avoid a crazy amount of interfaces in UI with dependency injection?

Problem I recently read a lot about Singletons being bad and how dependency injection (which I understand as "using interfaces") is better. When I implemented part of this with callbacks/interfaces/DI ...
1
vote
2answers
126 views

Should I be using IDisposable here, to properly manage memory?

Background I have an object that represents a test procedure that I need to run on a product. This object may be used multiple times during run-time, depending on how many times the user elects to ...
2
votes
3answers
301 views

Dependency Inversion Principle - No deriving from concrete classes?

I'm not sure if I am getting this right. In order to observe proper SOLID principles, am I forbidden to inherit from concrete classes? Does that mean that every concrete class that I have more or less ...
0
votes
1answer
31 views

Sdk building, declare dependencies inside the assembly or use external?

At my company, we're building an SDK consisting of a number of assemblies. For example, we deliver an assembly called Company.Platform.Security that contains the implementation of our authorization ...
-4
votes
1answer
204 views

Class library naming conventions [closed]

Typically in a C# program, the entry point is in Program.cs. However, if you are creating a rather generic class library, with no Main() method, such as TCPClient.dll what is the appropriate base ...
1
vote
2answers
84 views

Is it a good idea having default static variables for new instances?

OK let's say I have something like this: public class MyObject { public static int DefaultValue = 9 private int _value = DefaultValue; public int Value { get { return _value; } set { ...
0
votes
1answer
60 views

How can I avoid duplicating information in this scenario?

I have a Data class that can be placed inside a DataCollection class that can be placed inside a DataCollectionCollection class. Kinda like an egg can placed inside a box that can be placed inside a ...
2
votes
2answers
68 views

Ambient dependency injection through static service locator

After some googling I found some debates about whether constructor injection or property/field injection is better, but there is yet another alternative that strikes me as more beneficial. In most ...
4
votes
2answers
151 views

Service-locator anti-pattern alternative

I'm using Unity as IoC with C#, but I guess the question really isn't really limited to Unity and C#, but IoC in general. I try to follow the SOLID-principle, which means that I got very few ...
1
vote
1answer
53 views

Validating transaction codes with reference codes… Best way to encode the validation rules?

Good Day, I have a series of reference codes that my end users create during the course of the day. These reference codes correspond to a transaction code that is stored in a database. As of now, ...
1
vote
0answers
51 views

MVVM approach to mahapps.metro Dialogs

I want to use a ShowMessageAsync method, but, at first sight, there is no obvious way to do ViewModel binding, even though there are already a certain number of answers and examples about this. Now, ...
-2
votes
0answers
68 views

Maintaining a Unique id within List in two different iterations

I am struggling to create an algorithm which fulfills my requirements. I have a class which shows my FinalDestinationName and Time for the train to arrive to reach platform let's say like this ...
1
vote
1answer
95 views

What is the correct reusable architecture using Entity Framework for common database tables and services?

Context I have a line of business application "MyApp" in C# using EF. Layers are separated as MyResusableLib.DataAccess // Class Lib: EF based utils, extension methods, MyApp.DataAccess // Class ...
9
votes
3answers
313 views

How to share a code base among 10+ projects and minimize pain?

I have a number of applications that share the same data in the same database. To try and minimize redundancy of code the Data Access Layer is a shared project. This prevents each project from needing ...
1
vote
0answers
65 views

Using delegate to handle cross cutting concerns

I am planning to write a net-core library for using with n-tier architecture. In this architecture, i want to handle cross cutting concerns(audit, error handling, logging, validation, transaction ...
1
vote
1answer
235 views

Does anybody still use TODO for writing code later on? [closed]

Statement I often find myself still writing the following statement all over my code: // TODO: (the work that needs done) I do this in order to flag that I need to come back and do something later ...
0
votes
1answer
184 views

How to structure Restful API client files in C# project?

I've developed a Restful API in PHP, now the API makes different resources available like: Article, User, Service, Trace etc.... I'm going to implement each resource in a portable DLL, so I can use ...
4
votes
6answers
10k views

Better way of storing key-value pairs in the database?

I have a C#/SQL Server program that sometimes needs to store data. The data could be a response from a web service, a result of a database query, or any number of other things. There's no way of ...
2
votes
1answer
52 views

Writing Automated test cases for a folder Archiving Class.

Using C# and Visual Studio, I've developed a class that zips and archives a folder into desired location, creating directories and manipulating files on a machine. The intended use is as an part of ...
3
votes
1answer
215 views

How to pass data to OOP objects?

I'm new to this whole thing, so please tell me if I'm doing this wrong of if there's a better spot for my question. I'm making a game with basic systems for projectiles, npcs and items. This game ...
4
votes
4answers
5k views

How to treat “The field is never used” warnings?

Warning 1 The field 'MCS_SPS_School.Fees.DiscountAmt.rtvalue' is assigned but its value is never used G:\Jagadeeswaran\Nov 17\MCS-SPS School\MCS-SPS School\Fees\DiscountAmt.cs Warning 2 ...
2
votes
3answers
174 views

Giving a class many constructors and assigning via them as many properties as possible

I have written a class which represents a SQLite Trigger. public SQLiteTrigger(string Name, string On, TriggerStartType StartType, ...
2
votes
2answers
137 views

Best way to enforce constraints in Class

I have a class, something like this one (C#): public class MyFavoriteClass { public string Name { get; set; } public string Description { get; set; } (...) public ReferencedClass1 ...
3
votes
2answers
158 views

Write unit tests for the libraries, or just the application?

Background I am fairly new to unit testing, and have been recently using the Visual Studio Test Manager to create my Unit Tests. The way that I have currently been doing things is as follows: ...
1
vote
3answers
124 views

Should I use nameof to avoid repetition in constants?

In C#, I sometimes use: const string FirstName = "FirstName"; const string SSN = "SSN"; ... var ssn = GetValue(key: SSN); // e.g. GetValue fetches value from some key/value store to avoid ...
1
vote
3answers
318 views

Do I have to fork a server program as an “C” child process in order for correct interprocess communication to take place?

I would like to implement interprocess communication between an Ubuntu Linux 15.10 mono 4.1.2 C# recorder client and Ubuntu Linux 15.10 mono 4.1.2 C# video server using a C++ mutex class and C++ ...
-1
votes
2answers
102 views

Do you say “this” on protected members? [closed]

Background I have never had a formal class in OOP/OOD although I understand how the protected members work. Being accessible by any instance/derived class, they are thereby less private (more ...
2
votes
2answers
120 views

Method to validate an object - should I have one method encapsulating all validation logic

I have a class, Customer which has some basic properties on it such as firstname, surname, email, dateofbirth. I have written another class called CustomerValidation which currently has one public ...
2
votes
1answer
98 views

Should I use BackgroundWorker in Pipeline pattern?

I am planning the implementation of a Pipeline pattern as seen in this MSDN article. This is a WPF application for which I need to monitor progress of each stage of the pipeline in order to display it ...
1
vote
1answer
100 views

why exposing service instead of repository in onion architecture

I'm digging on how to structure projects and so I stumble into Onion Architecture. As to how I understand it, its more on a domain-centered-focus architecture instead of a database-driven type. I'm ...