Questions tagged [c#]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
2k views

Session Flash vs TempData C# MVC 3

A little background. A developer I used to work with insisted on disabling Tempdata and using Session Flash for passing data in the return view. Question is, is there any advantage to doing it ...
8 votes
2 answers
8k views

Why do we need to use sealed on a class? Do we really need sealed?

Reading this article (by Eric Lippert), it has four arguments as to why you should use sealed, however, I don't understand why we actually need it. Philosophical/aesthetic reasons aside, why do we ...
0 votes
1 answer
146 views

How can I allow sub-services to use concrete types, without having an ever-growing type argument list on the primary service?

NOTE: I believe I have a bit of an X/Y problem here, so please, bare with me. Also, I have trouble explaining things sometimes, so feel free to ask me to elaborate, and I will improve anything I can ...
3 votes
3 answers
2k views

Design pattern to force client of a class to call a method

I have a large class with complex properties. I'd like to introduce a default implementation, allow the user to override part of the default implementation and also make sure the user calls a sync ...
0 votes
0 answers
21 views

Is the combination of Image Classification and numerical data useful and possible with ML.Net?

Up front, this is my first ever question on StackExchange. So please be gentle with me. It is also my first time working with Machine Learning and ML.Net which means that I'm lacking fundamental ...
1 vote
3 answers
63 views

Multi type HTML dropdown conversion to the corresponding C# object type

Note: This is a contrived example I came up with to illustrate what I'm after as simply as possible. I have an HTML report with a single dropdown box at the top that lets the user select (or filter) ...
0 votes
1 answer
62 views

Best Way to name derived classes when extending its functionality C# [closed]

I have just recently joined a new company and One of the classes used to log information has not been written properly. So i have been asked to add new functionality to the logger. So rather than ...
5 votes
2 answers
1k views

Data Repository and Complex Queries (DTO)

Following the classic 3 layer architecture domain Model (a list of domain models live there and has no dependencies) DAL layer - My Repositories lives there with DBContext implementation (Ado.net) ...
7 votes
3 answers
19k views

What is meant by Scope of a variable?

I think of the scope of a variable as - "The scope of a particular variable is the range within a program's source code in which that variable is recognized by the compiler". That statement is ...
41 votes
8 answers
4k views

Can modern OO languages compete with C++'s array store performance?

I just noticed that every modern OO programming language that I am at least somewhat familiar with (which is basically just Java, C# and D) allows covariant arrays. That is, a string array is an ...
1 vote
1 answer
180 views

Designing asp.net core web api to add sub classes/specialized objects

I have not worked with EF for a while. As an exercise, I am writing a core web api that allows keeping track of a user medias. A media can be a postcard, a photo album, a recording, a book... I would ...
1 vote
2 answers
60 views

Domain Driven Design - Aggregate Root and Nested Aggregate Invariants

I've come to a bit of an impasse with the best way to implement a DDD problem, and am hoping for some advice from those with more experience, please. I have a RecipeCollection, which has a collection ...
5 votes
1 answer
8k views

Implementing a DAO for entity framework [closed]

Could anybody help me to find a good tutorial about how can I implement DAO pattern and also tools that help me to create this classes in automated way.
4 votes
3 answers
480 views

What's a RESTful url for a linked item?

This is going to be a web service that returns a JSON object. Currently, I'm using C# technology and simply using ASP.Net MVC to create the calls. This is not a web page, so SEO is not a concern. I'...
2 votes
2 answers
198 views

How to split logging into streams?

I am looking for an advice (or an example) on how to organize logging streams in my cloud app (C#). In my app there are logging events related to the application infrastructure level and I want to ...
9 votes
1 answer
461 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 ...
2 votes
6 answers
1k views

How assertive should I be in handling exceptions in objects?

I have been writing in C# 4.0 a lot lately and trying to write as lean as possible. As such, I have not been using the classic try/catch blocks and using statements as often. I understand the general ...
2 votes
3 answers
390 views

Best way to generically convert SQL-Based classes to DTO using Class Name in C#?

I have a collection of classes in a SQL database that all share the same structure, and cannot be changed. They are similar to the example below. I am using Entity Framework Core and would like to ...
0 votes
1 answer
288 views

Data Integration Design Using Microsoft SSIS

I am working on a data integration project, where I need to extract data from oracle source and load it to XML file. The requirement is to get the list of customers and foreach customer create an xml ...
2 votes
1 answer
345 views

GetOrCreate method for a database operation

I have read this thread: Is it bad coding practice to create something in a get if it does not exist? But, my question involve a method which gets a record from a database or creates it if it doesn't ...
10 votes
3 answers
2k views

How should I handle logging when I create libraries for others?

All. I am creating some libraries for other teams in my company. They all have different logging mechanisms. I want to provide trace information of what my libraries are doing. What should I to ...
20 votes
4 answers
12k views

What naming convention for C# file that contains multiple classes?

In C# projects, we frequently group small and tightly related classes into the same .cs file. This practice reduces the friction of dealing with a myriad of files containing close to no actual code. ...
8 votes
4 answers
4k views

Why are public and private accessors considered good practice? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Why exactly is having public and private accessors like these: private string foo; public string Foo { get { return ...
0 votes
0 answers
16 views

Access ViewModel in ObservableCollection by Underlying Model

I have an ObservableDictionary that I bind to a ListView. The ObservableDictionary contains ClientViewModels which are ViewModel wrappers for my Client model that contain UI-only properties. The ...
0 votes
1 answer
57 views

Is there a best practice for storing multiple pages of JSON responses from an API?

Scenario: An API that responds to a request with multiple JSON objects contained in an array. The responses are paginated such that each page returns an array of JSON objects. I deserialize the JSON ...
2 votes
2 answers
481 views

How does this pseudo-RAII implementation allow for a scoped lock in C#?

For the concurrency programs I have been writing in C#, my locks/synchronization tend to follow this pattern: try { Monitor.Enter(locker); // critical region } finally { Monitor.Exit(...
1 vote
1 answer
1k views

C# Structs, 16 byte rec. - Are getters and setters included in that?

I was reading into the nitty-gritty of structs in C# here: "C Fundamentals, The differences between struct and class." and at the very bottom it mentions keeping a struct below 16 bytes. I ...
0 votes
1 answer
168 views

Best way to accept a lot of user input from command line

I have a program that accepts computer names and then will perform CIM session tasks. The computer names are passed in from the user input and separated by "," (ex: program.exe -computers ...
20 votes
2 answers
5k views

Abstract exception super type

If throwing System.Exception is considered so bad, why wasn't Exception made abstract in the first place? That way, it would not be possible to call: throw new Exception("Error occurred."); This ...
2 votes
2 answers
247 views

How to come up with an easy-to-use way of creating quantities with units in C#?

I want to come up with a way to make it easy to write classes that represent quantities with units, such as length, weight, etc. For example, var height = new Length(32.2, LengthUnit.M); var weight = ...
0 votes
1 answer
54 views

MVVM - Wrapping Class For ViewModel

I am using a networking library I created which contains a Client class. I have a GUI which will display all these clients in a ListView with columns, such as one containing their online status. The ...
30 votes
6 answers
26k views

Is There a Real Advantage to Generic Repository?

Was reading through some articles on the advantages of creating Generic Repositories for a new app (example). The idea seems nice because it lets me use the same repository to do several things for ...
16 votes
3 answers
10k views

How will C# 5 async support help UI thread synchronization issues?

I heard somewhere that C# 5 async-await will be so awesome that you will not have to worry about doing this: if (InvokeRequired) { BeginInvoke(...); return; } // do your stuff here It looks ...
28 votes
5 answers
7k views

Do not declare interfaces for immutable objects

Do not declare interfaces for immutable objects [EDIT] Where the objects in question represent Data Transfer Objects (DTOs) or Plain Old Data (PODs) Is that a reasonable guideline? Up to now, I've ...
6 votes
9 answers
14k views

What are the hardest parts of the C++/C#/Java programming languages? [closed]

Just wondered what are the features of the three main programming languages which show you are an 'expert'? Please exclude 'practical' skills such as indenting. Am I right in saying for C++ the most ...
1 vote
2 answers
145 views

C# - Class creating instances of other classes requiring different services

Context I have a service class whose sole purpose is to interact with a specific API, let's say the Automotive API. The API mostly works with generic AutomativeRecord which basically represents a ...
10 votes
5 answers
41k views

Is it possible for two DLLs to conflict , preventing solution to build

Though I have a specific case, but I was wondering about the general situation. Can two DLLs, when added as Reference to a Visual C# project collide with each other to prevent the solution from ...
1 vote
4 answers
1k views

Should an MVP/MVC Model contain behaviour?

I have read plenty of questions on here, which appear to confuse the MVP/MVC Model with the Domain Model. In my mind the MVP Model calls the Service, which then calls a rich Domain Model i.e. the MVC/...
0 votes
0 answers
76 views

WPF - Custom MenuItem with buttons or new Window? (or other?) - Update : what is your opinion of my solution?

Context I'm currently doing a project with WPF, which I'm fairly new to. What I am trying to do is a custom and configurable taskbar-like application. What I currently have I managed to create a ...
0 votes
1 answer
4k views

I/O interface for portable library

I'm writing a new .NET portable library that can read a file format, and file I/O is not available for portable libraries. The article "How to Make Portable Class Libraries Work for You" ...
7 votes
6 answers
2k views

Any alternative main stream programming methodologies to OOP using C#?

As far as programming languages go, I love C#, and for that matter all the good that comes from the .net framework (LINQ, etc). My main concern is I seem to be churning out too much code, and using ...
2 votes
2 answers
297 views

Can a query handler (not repository) access a web service?

Say I have the following class, which maps to a database table: public class Person { public Guid Id {get; set; } public string Name {get; set; } public DateTime DateOfBirth {get; set; } ...
6 votes
1 answer
3k views

ASP.NET Core - Is using [FromServices] attribute bad practice?

I have a Controller in ASP Core MVC. I'm trying to trim down the dependency injected services in the constructor so I can start building unit tests more easily. However, I have some services being ...
0 votes
2 answers
149 views

Struggle with catch 22 in initialization code

I have a command line application written in C#. Here's some facts about the program that are relevant to my question: The application has a "data directory" (e.g. ~/.config/myapp) where ...
0 votes
1 answer
134 views

In CQS is it accepted to have a coupling to another command

Consider this code, rather than hardcoding the hour when we execute a certain command I query the CQS engine and asks when it will be executed. Though now we have a high coupling to another command. ...
-1 votes
2 answers
206 views

Would Injecting dependencies in C# as default parameters be a bad practice?

Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
2 votes
1 answer
963 views

How to authorize and store user login from a xamarin frontend to a asp.net core api

So I suppose this question isn't as much as a 'How to' but a 'which way' kind of question. So I have a .net core api backend that makes calls to a dB I also have a xamarin forms project that ...
0 votes
5 answers
6k views

Why is an interface used rather than inheritance?

Please see the Rules Design Pattern on this webpage: http://www.michael-whelan.net/rules-design-pattern/. It has classes like this: public interface IDiscountRule { decimal ...
0 votes
1 answer
747 views

Best way to store ListView Data(ListView.Items) into file

I just came across this question telling how to store ListView Data(basically ListView.Items) into a text file but it got me thinking that, is it the best way to do it? In terms of efficiency, ...
0 votes
3 answers
143 views

Hardcoding endpoints in library alternative

I'm dealing with creating a few internal libraries for a project that can offload emails and logs to a queue (Service bus, storage queue). The issue I'm having is how to configure the the queueing ...

1
2 3 4 5
96