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
4
votes
1answer
3k views

Should I use a boolean or a cancellation-token to stop this task?

I have a program that starts a task as follows: token = this.tokenSource.Token; var t = Task.Factory.StartNew(() => { while(!token.IsCancellationRequested) { // do the work... ...
3
votes
6answers
2k views

“As” Naming Convention [closed]

I'm experimenting with a naming convention I've devised and am seeking opinion. It involves the use of an "As" infix, and at this point I am envisioning it in the context of JavaScript, C# and C++ ...
3
votes
2answers
3k views

What do you suggest for cross platform apps, including web

I have always preferred cross platform development over most other concepts as long as I can remember. Which is one of the reason I never got into .Net. Currently, I use php/javascript/python as my ...
3
votes
5answers
2k views

How to turn on/off code modules?

I am trying to run multiple sites using single code base and code base consist of the following module (i.e. classes) User module Q & A module Faq module and each class works on MVC pattern i....
3
votes
1answer
646 views

Can two objects have multiple types of relationships?

Say I have a many to many relationship in the database like this: CREATE TABLE Person (ID int, name varchar(100), dateofbirth datetime, Gender char(1), primary key (ID)) CREATE TABLE Sport (ID int, ...
3
votes
1answer
1k views

Help understanding modeling in domain-driven design

I've been trying to learn domain-driven design (and similarly Onion Architecture) the last week or so. I think I've got an understanding of it, but like math, I suck at extracting all of the details......
3
votes
3answers
540 views

Pre-processor usage to separate logic to different versions of product

In the .NET code base of a product, there are #if pre-processor statements to define whether certain functionality should be available. Like so: shared logic #if version1 some logic #endif #if ...
3
votes
1answer
312 views

How to generate a Natural key for a Domain entity?

I was reading this question recently: ID properties on Domain objects in DDD The question talks about having an surrogate key in the infrastructure layer, which is a database ID. I use a Guid for ...
2
votes
3answers
915 views

What should I name these methods? [closed]

I have two interfaces, one with and one without generic type parameters. The non-generic interface is used internally so that I can store instances of the generic interface in a collection. All would ...
2
votes
2answers
801 views

Where to place configuration files sources

I am developing a C# windows service application, which have different configuration files for development, for production system, for test system, like: Dev.config Test.config Prod.config Now we ...
2
votes
2answers
426 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 ...
2
votes
1answer
328 views

Is an administration facility a bounded context in its own right?

Say I have a DDD application with three bounded contexts i.e. Sales, Production and Marketing. Say I wanted to setup an administration facility. The admin facility would allow superusers' to change ...
2
votes
3answers
2k views

if a c# interface contain only getter and setter definition, is it a code smell?

A project that I am working on has the following code for interface example: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { public ...
2
votes
2answers
217 views

Should I use the Primary Key field when comparing two DDD Entities using: .Equals

Say I have a class like this: public abstract class Product { public Guid id {get; set;} public string description {get; set;} } This class is populated from the database. ...
2
votes
3answers
2k views

Switch Parent Children relationship in C#

Using C# and WPF I have a situation where my data is organized hierarchically. I am using a treeview to represent this : Group_01 Object_01 Material_01 Texture Material_02 Texture_02 Group_02 ...
2
votes
2answers
2k views

Pattern for multiple datasources

I've already read this question on CodeReview. I was hoping for general advice. I'm writing a service which will go to numerous data sources. Each source requires getting copious amounts of data ...
2
votes
3answers
1k views

File storage for a blog component: database or filesystem?

I'm going to develop a fairly basic re-usable blog component, with simple CRUD operations using ASP.Net. Which method of storing blog posts would be best suited to the situation in terms of ...
2
votes
2answers
1k views

Invoke model logic in one UserControl from view-model in another UserControl without violating MVVM

Here is WPF application consisting from 3 UserControls: UserControl3 is a part of UserControl2 content. I keep MVVM during developing and using Prism. I need to invoke custom class method (which is ...
2
votes
1answer
261 views

Repeating Interface inheritance declarations

Take the following example: public interface ISerialRVD { RouteValueDictionary ToRVD(); } public interface IViewModel : ISerialRVD // Here? { Int32 Page { get; set; } String Action { get;...
2
votes
6answers
4k views

Class Design — Multiple Calls from One Method or One Call from Multiple Methods?

I've been working on some code recently that interfaces with a CMS we use and it's presented me with a question on class design that I think is applicable in a number of situations. Essentially, what ...
2
votes
2answers
753 views

Approach of delivering “Logging API”

I faced a question in a .NET interview. As a client i need a LoggingAPI. How you go the approach of design and development and delivering Logging API to the client? I don't care about WPF or a ...
2
votes
3answers
813 views

Which C# data structure should I use to quantify this information?

I am attempting to determine which data structure I should use for the following information: ("Water", 100F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, ""); ("Tuna", 60F, 184F, 30F, .01F, ....
2
votes
1answer
429 views

Use struct or not

I made a tiny wrapper for fluent precondition assertions in c#. Now basically in all public / contract methods i assert the values this way: Precondition .For(()=>Model) ....
2
votes
1answer
587 views

Class structure for Entity Framework

I'm using EF (Code first) and I'd like to isolate the properties from the methods (many of the methods reference other libraries that I don't want my database project to have to reference). As an ...
1
vote
1answer
305 views

Using Aggregation and Association

Say I have two classes: Customer and Invoice. The database tables look like this: CREATE TABLE Customer (ID int, name varchar(30), primary key (ID)) CREATE TABLE Invoice (ID int, date datetime, ...
1
vote
1answer
212 views

C# - Data-Driven Design & Coupling - Mother may I?

I have used data-driven design in the past and it has worked quite well. What I dislike about it is if you need some form of a string whose value has to be updated based on other values. e.g., "...
1
vote
1answer
322 views

Implementation of instance testing in Java, C++, C#

For curiosity purposes as well as understanding what they entail in a program, I'm curious as to how instance testing (instanceof/is/using dynamic_cast in c++) works. I've tried to google it (...
1
vote
1answer
298 views

Should I handle all nine comparisons?

I was reading this article here: http://enterprisecraftsmanship.com/2014/11/08/domain-object-base-class/. The article talks about creating a base Entity class, which handles four of the nine ways to ...
1
vote
4answers
3k views

Circular dependency and object creation when attempting DDD

I have a domain where an Organization has People. Organization Entity public class Organization { private readonly List<Person> _people = new List<Person>(); public Person ...
1
vote
2answers
2k views

share method logic along classes without inheriting from abstract class

In some languages (e.g. C#) a class can only ever have 1 base class which seems like a problem for what I'm trying to do. I will give you an example of what i'm trying to do, hopefully this will make ...
1
vote
1answer
123 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
427 views

Create an entity object in the domain layer when the ID is unknown

I am trying to learn the Rules Design Pattern as described here: http://www.michael-whelan.net/rules-design-pattern/ (towards the bottom of the webpage). I have written a class like this: public ...
1
vote
1answer
289 views

Does merely parameterizing a dependency meet the requirements for Inversion of Control?

When I find a concrete dependency inside an extension method, I have been attempting to remove the (concrete) dependency by parameterising it like so // original implementation public static List<...
1
vote
3answers
447 views

Is EF4 mature enough with MySQL or Oracle? [closed]

Is Entity Framework 4 with MySQL or Oracle mature enough to be used on production level web application? Can it provide high level of performance, or should we stick with just plain data access with ...
1
vote
2answers
2k views

embedding programming languages into other languages [duplicate]

In C/C++, there is a keyword that allows you to enter assembly language directly into a method. Example int Main() { __asm // notify the compiler that this block is assembly language. { ...
1
vote
2answers
3k views

Nested Try Catch Error Handling with Log Files?

Best practice question for error handling in C#? In our system we will be writing out files, and with each file they will have a corresponding error file. The error file will get written every time ...
1
vote
1answer
188 views

C# - How can I ensure a member is invoked without needing to call it and rely on the { get; }

I'm using reflection as a way of implementing a factory pattern: Type type = GetProviderType(vendor); ConstructorInfo constructorInfo = type.GetConstructor(new Type[] { typeof(...
1
vote
2answers
1k views

Class structure/pattern for validating several different Excel templates?

I'm trying to validate the contents of Excel sheets that follow several different templates. For each one, there are three possible validation actions for various cells: Regex (e.g. "XYZ-123" fails ...
1
vote
1answer
647 views

MVVM, is it better suited for web applications or GUIs?

I am currently deciding whether I should implement a new system with a web application as a front-end, or if I should instead produce an executable file using WPF. The pattern that I will use is MVVM,...
1
vote
3answers
4k views

Most efficient method for large switch statements

Let's say you have many paths that an application can take at a certain point based on the value of a specific input (for example a simple int). Is there a certain method that is most efficient for ...
1
vote
3answers
771 views

Guidance for a C# developer to become better UI developer

I am a C# developer and had developed simple websites in regular asp.net(with asp.net controls) and a wpf application. Nowadays, I am trying to learn Asp.net MVC3 and I have been exposed to HTML ...
0
votes
2answers
564 views

Should a class validate argument using external method/service with unit testing?

I have a class that runs as a service and returns html code of a website when supplied with a URL. The code: public interface IHtmlDownloader { IWebProxy Proxy { get; set; } string UserAgent ...
0
votes
1answer
589 views

Factory Design Pattern Implementation with multiple interfaces and base class

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
0
votes
3answers
373 views

Should I pass an ID number from the feature file?

Say I have a domain object like this: public class Customer { private Guid _id; private string _name; private Address _address; public Customer (Guid id, string name, Address address)...
0
votes
3answers
2k views

suggest structure for classes that maps to json with dynamic data without using dynamic or object reference

this is a kind of data i have to de-serialize { "id": "M:11427", "title": "DAX30", "nextStartId": "S:727831", "sections": [ { "type": "HIGHLIGHTS", "...
0
votes
1answer
322 views

Should Domain Entities be dependant on factories?

Please see the code below: public IEnumerable<DenominationNumberRequired> CalculateDenominationsFor(int cost) { var target = cost; foreach (var denomination in currency....
0
votes
2answers
3k views

How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”

I am working on a C# net micro framework project, in particular an I2C bus management/class. I have several different I2C devices each defined in separate classes which contain all of the devices' ...
0
votes
1answer
848 views

C# Application GUI design dependent on configuration

I have built quite big WinForms application working in industry for a few years. It communicates with many HW devices. Application can be configured to use or not use some of these devices and GUI is ...
0
votes
1answer
24k views

What is the benefit of using getters and setters on properties in C#? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Why do we use get and set method in C#? And why do we use public and private method property? For example: public class Date { ...
0
votes
2answers
101 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; } public ...