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

7
votes
1answer
406 views

I need to be able to adapt my type to theirs, and theirs to mine

I have a situation where I have an external library. In short, I need to be able to adapt my type to theirs, and theirs to mine. The library has a collection like so: interface IExternalCollection { ...
0
votes
0answers
15 views

Should I recreate entity of proxy or inherit it?

I am using an external service, which is referenced as a service. There is an auto-generated entity User, and I can easily acquire it using proxy client: [System.CodeDom.Compiler....
1
vote
2answers
117 views

Will it be okay for an interface to take a dependency on an interface in this situation?

Background I have an interface defined for a circular-buffer called ICircularBuffer in a separate project. This ICircularBuffer is something that we use all over the place, so it resides in the ...
5
votes
3answers
150 views

Verbose Return Types

I've recently been writing some code that deals with 3rd parties -- obviously errors will happen so I'm using Either/Maybe monads where appropriate. As this is C# I'm also using async Tasks too. My ...
0
votes
1answer
116 views

Sharing information between two independent application

I have to share parameters/information between two independent applications: an Executable and a PDF file. By clicking a button within the pdf I want to perform some specific task (or run code) in my ...
0
votes
0answers
89 views

Should I design my Unit-Of-Work like this?

I am using .net and Entity-Framework (EF) on the back end and I would like some advice on this Unit-Of-Work (UoW) implementation. Should I create a unit of work with one entity and multiple services? ...
1
vote
2answers
110 views

How to do dynamic dimension for loops

I have a for loop in C# as below, int[] dim1, dim2, dim3; //Initialize dim1, dim2 and dim3 for(int i = 0; i < dim1.Length; i++) { DoSomething1(i); for(int j = 0; j < dim2.Length; j++)...
3
votes
2answers
130 views

Creating instances of an interface through a static method

Is the following design flawed? Basically I have a main class used to create an object of a type and then return it as the main interface of the type. The problem with this is that each of the ...
3
votes
0answers
87 views

Generic request processing

I got a webservice that accepts multiple calls that require different handling and validation, using generics I've managed to create a common class that accepts a handler and a validator and it looks ...
-3
votes
1answer
154 views

Any languages where string default value = “”?

Are there any programming languages where the default value of a string is "" ? If so, what are they?
0
votes
2answers
92 views

Injecting a factory with multiple constructor parameters

Initially I needed only one queue to be created by the MessageQueueFactory: container.RegisterSingleton<IMessageQueueFactory>(() => { var uploadedWaybillsQueuePath = ConfigurationManager ...
0
votes
1answer
70 views

Matching objects of different types without violating SOLID/minimizing dependencies

I have two separate inheritance hierarchies that represent objects that can be "matched" to each other to consitute a FooBarMatch (which contains references to the matched FooBase and Bar partners): ...
1
vote
2answers
170 views

API Design: Should I use strings or an enum for dictionary keys

I am working on an API in C#. I am trying to think about the simplest way to expose my API for consumers of it. In particular, I have a class in my exposed data model that has a dictionary property. ...
-1
votes
1answer
130 views

What should I consider when scraping content from 6k+ Websites?

I am working on a project that will scrape data from roughly about 6,000 websites. I am considering using a server/client model in which the server is responsible for scraping the data and importing ...
1
vote
0answers
35 views

XElement.Parse and querying versus serialization (strongly typed objects)

We have a rather large code base that interacts with many SOAP based XML services. Each one of these services makes 1 to n service calls A typical low level web service call looks like this (...
-1
votes
0answers
67 views

Where is the implementation for Win32Native.WriteFile()?

I'm trying to go down the levels and see how Console.WriteLine() works. I've narrowed it down to this: Win32Native.WriteFile() Which you can find here: https://github.com/Microsoft/referencesource/...
2
votes
2answers
224 views

What does Console.WriteLine() call behind the scenes?

I'm interested in how calling Console.WriteLine() actually displays text. I've had a look at the source code from: http://referencesource.microsoft.com/#mscorlib/system/io/textwriter.cs,...
-3
votes
0answers
29 views

Parameter with Multidimensional array & params keyword

By using params keyword with 1D array in method declearation, we can pass variable number of arguments without populating arrays. Why it is compile time error when we use params keyword with ...
1
vote
0answers
56 views

Two classes which are supposed to be the same, but differ in lists

I am using a 3rd party API which yields JSON which has two ways of loading data - as a list of items, or as a singular item. The problem is that a given item in the list has different properties than ...
4
votes
7answers
497 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
43 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
56 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
65 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 ...
0
votes
0answers
47 views

Serializing .NET object into a JSON string produces unreadable output [migrated]

I'm trying to convert a .NET object into a JSON string, because I want to be able to read the content of this object in the client side. Here is my controller code: public ActionResult Index(...
9
votes
4answers
499 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
738 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
132 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
194 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
0answers
78 views

How to add and use a database in a C# project in Visual Studio 2015? [migrated]

I'm learning C# for about 7 months now, and currently I'm studying LINQ. I worked with local collections, but I'd like to use it with databases too, and learn how to use a database in a program. The ...
2
votes
1answer
124 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
520 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
62 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
182 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
94 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
120 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
64 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
136 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
286 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
232 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
34 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
189 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
375 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
208 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
113 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
178 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
170 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
87 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
117 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
167 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
72 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 ...