Questions tagged [.net]

.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

Filter by
Sorted by
Tagged with
45 votes
3 answers
6k views

Benchmarking things in C#

I needed a better way to benchmark code, because, well, rewriting the same benchmarking code every time I need it is just...well...unpleasant. So, here's a class which does just that, it runs an <...
Der Kommissar's user avatar
40 votes
3 answers
11k views

Exporting doc types using queues and multithreading

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
JonathanPeel's user avatar
36 votes
6 answers
5k views

DisposableObject base class for C#

I commonly run into the need to implement IDisposable in my code. To correctly dispose of both managed and unmanaged resources requires a reasonable amount of boilerplate code. Based on the ...
Nathanael's user avatar
  • 765
33 votes
3 answers
49k views

Entity framework with repository and Unit Of Work pattern and POCO architecture

This is my architecture to EF4 using repository pattern and unit of work pattern with POCO. I believe I made some mistakes. I have a solution with 5 projects: ...
Naor's user avatar
  • 515
31 votes
6 answers
3k views

Extensible code to support different HR rules

Recently, I got challenged to code with following bullet points: Extensible code to support different annual leave rules for HR departments Maintainable code to add/change the existing rules without ...
Simsons's user avatar
  • 723
29 votes
5 answers
51k views

Type-safe Dictionary for various types

Assume the following situation: you have an object that can store any object based on a key (basically, IDictionary<string, object>). You want to store ...
svick's user avatar
  • 24.2k
28 votes
2 answers
16k views

Reusable Unit Of Work Interface / Factory

Given my IUnitOfWork interface using System; public interface IUnitOfWork : IDisposable { void Commit(); } I then ...
Issa Fram's user avatar
  • 409
28 votes
1 answer
7k views

Fluent LinkedIn REST API client interface design

There is a handful of LinkedIn clients written in C# on the NuGet package library, but as far as I can tell, most only do authentication via LinkedIn. I found a couple which offer a LinkedIn REST API ...
danludwig's user avatar
  • 411
26 votes
2 answers
128k views

Implementing a good TCP Socket Server

I'd like a code review on my very simple server application that validates whether the serial number retrieved from the client is a valid one or not. Is there a better way to handle the start/stop ...
TtT23's user avatar
  • 1,040
23 votes
5 answers
21k views

Best way to pass parameters to Factory class?

So I have a series of objects, which I will call Impl1, Impl2, and Impl3. They each implement an interface, called IImpl. I have a Factory class who's task is to retrieve the ImplX which is ...
GWLlosa's user avatar
  • 451
22 votes
4 answers
46k views

Building a Tree from a flat List<Nodes>

This is my incoming data: ...
SNag's user avatar
  • 321
22 votes
2 answers
57k views

Creating a thread-safe list using a Lock object

Will this code qualify for a truly thread-safe list? It is using the Lock object. ...
Mrinal Kamboj's user avatar
21 votes
3 answers
16k views

Determining if a connection has been made to a communications device

I am unsure if my use of Monitor.Wait and Monitor.Pulse is correct. It seems to work alright, but there is a nagging doubt I am ...
Andy's user avatar
  • 343
20 votes
4 answers
9k views

Matrix class in C#

I've been learning C# during my free time in the past months; before that, I was mostly writing Java, so the transition hasn't been too hard, but I've never had my code reviewed or read by someone ...
cliesens's user avatar
  • 558
19 votes
8 answers
3k views

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

I was reading this question, and the answer that mentioned streams, and a thought had occurred to me. In many cases (at least in my usage) I want to determine if a sequence (or ...
Der Kommissar's user avatar
19 votes
2 answers
96k views

Displaying data from a database onto a form

I'm a beginner to .NET and could you guide me to right direction. My problem is based on the following code. Here I have 4 variations of same method and all 4 variations are working fine. What is the ...
CAD's user avatar
  • 1,753
19 votes
2 answers
1k views

Enforcing string validity with the C# type system

One of my biggest complaints about .NET is that there's no way to guarantee a string match a certain type in the type-system. Note This started as more of a proof-of-concept than a real usable system,...
Der Kommissar's user avatar
19 votes
3 answers
10k views

scoped_ptr for C++/CLI (ensure managed object properly frees owned native object)

Motivating SO question: Is there a C++/CLI smart pointer project (e.g. scoped_ptr)? I'm interested in any reviewer comments, and especially identified bugs or inconsistencies with the native ...
Ben Voigt's user avatar
  • 852
18 votes
3 answers
10k views

Change desktop background

I've created a simple program that downloads an image (different image every day), then sets it as my desktop background. It is a console application, and closes immediately after downloading the ...
Josue Espinosa's user avatar
17 votes
5 answers
2k views

Populating a ListView with Items

I populate a ListView with Items. Each Item has data attached to its .Tag property. Over time, I have needed to handle many cases where something would be null or ...
NDEIGU's user avatar
  • 273
17 votes
1 answer
58k views

Method that returns description attribute of enum value

I have the following method in .NET Core that returns the description attribute of an enum value. I think this code can be more elegant. I'd appreciate some ...
Sam's user avatar
  • 335
17 votes
3 answers
2k views

Simple Linked List

I've implemented a simple linked list in C# using generic T for values. I did not inherit from any of .Net's fun and helpful classes like ...
BenVlodgi's user avatar
  • 4,278
17 votes
2 answers
16k views

Secure password hashing

I have found a password hashing article and an implementation. Is this code secure if I increase the salt to 64 bytes, hash key size to 128 bytes and the iterations to 10000? Are there ...
SetiSeeker's user avatar
16 votes
6 answers
18k views

Determine if an image is opaque or transparent

I wrote an extension method defined for the Image Class (System.Drawing) — which returns a Boolean value telling you if the image is opaque or transparent. The color of each pixel in the image is ...
Owen's user avatar
  • 1,484
16 votes
4 answers
584 views

Entities and the things they do

So I have an Entity, which is responsible for providing an abstract base for other objects to inherit. (Like Actor objects, ...
Der Kommissar's user avatar
16 votes
4 answers
1k views

Is decoupling necessary for very small applications?

I threw together a small solution for my organization today for some basic data review and approval procedures. This particular application will likely not change or add functionality at any time. ...
Evan L's user avatar
  • 291
16 votes
1 answer
356 views

Open source project to ease the Assert part from the functional tests of .Net Core Web APIs

I have built an open-source project based on FluentAssertions in order to solve some recurring tasks I was doing while testing the .Net Core APIs I'm developing. I find the capability of doing in ...
Adrian Iftode's user avatar
15 votes
5 answers
41k views

Finding elements inside ExpandoObject

Is it possible to simplify the code below? ...
user2926340's user avatar
15 votes
2 answers
10k views

Guitar Hero III Bot

I made a Guitar Hero III bot for PC. I was able to beat the song "Through the Fire and Flames" on Expert with the bot which can you see here. If you watched the video, you can see that the bot misses ...
Owen's user avatar
  • 1,484
14 votes
7 answers
47k views

Regex validation for Email Address

I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct: Wiki Link Local_part The local-part of the email address may use any of these ASCII ...
Idothisallday's user avatar
14 votes
6 answers
4k views

Showing various network information from a NIC card

I have included the code from a second year project that I would like some advice on. Basically it utilises WMI to query a NIC card from a selection (depending how many are installed in the host ...
Dylan Jackson's user avatar
14 votes
7 answers
1k views

Binary Heap where a comparison delegate is used

I currently have a Generic Implementation of a BinaryHeap. It must be able to maintain it's integrity with elements that may or may not implement ...
BarelyTilted's user avatar
14 votes
5 answers
1k views

Reusable implementation of IComparable<T>

I often find myself implementing IComparable{T} in different classes for sorting in a very similar fashion: Values meeting criteria X and Y should be sorted to ...
JamesFaix's user avatar
  • 289
14 votes
6 answers
1k views

Form to create new students or view existing student information

I started out with the best of intentions, but this form got hacky real fast. It's purpose is to serve as a create new Student form. Also, if you want to view an existing Students information. Think ...
user avatar
14 votes
9 answers
1k views

How can I refactor to avoid repetition finding the index of strings in a list?

I have a list of strings where I want to find the index of a first- and second-choice video compressor. Logic: If the first choice is available, return its index. If not, and the second choice is ...
JYelton's user avatar
  • 307
14 votes
4 answers
2k views

Making a web service call based on a type of request

I have my code which makes a web service call based on a type of request: ...
Simsons's user avatar
  • 723
14 votes
3 answers
31k views

Convert string to multiline text

I made this method that takes any string and transforms it into a multiline text l; each line having the max (character) length specified by the rowLength parameter....
Gabriel Andrei's user avatar
14 votes
3 answers
19k views

Design pattern for implementing multiple data sources

I've written a program to populate a particular object from multiple data sources, however I'm not convinced I'm going about this in the right way: I have no idea which (if any) design pattern I have ...
James Law's user avatar
  • 497
14 votes
2 answers
35k views

Mapping ExpandoObject to another object type

I am working on a helper method that maps properties from an ExpandoObject to a user supplied object and was wondering if the code could be cleaned up or made any ...
Tom Bell's user avatar
  • 243
14 votes
3 answers
23k views

Timing out a method

I have created this extension method that can be used to run a function with a timeout applied to it. Is this a sensible way of doing it? ...
Rob White's user avatar
  • 281
14 votes
2 answers
18k views

Listing the weeks in a given month

I need to take a month (defined as a start and end date) and return a set of date ranges for each week in that month. A week is defined as Sunday through Saturday. A good way to visualize it is if ...
Mike Christensen's user avatar
14 votes
1 answer
6k views

ResettableLazy<T>: a resettable version of .NET Lazy<T>

I implemented a resettable version of .NET Lazy (context: mostly to use it in a MemoryCache for auto refresh purposes on item expiration) This is a very naive implementation and I am pretty sure ...
Natalie Perret's user avatar
13 votes
3 answers
5k views

What do you think of this improvement of Linq's GroupBy method?

Linq already has a set of GroupBy methods for enumerable, which returns IEnumerable<IGrouping<TKey, TSource>>. I dislike this return type because it ...
Louis Rhys's user avatar
13 votes
5 answers
13k views

Is this Repository Design Pattern Valid and efficient?

I am using Dapper ORM in my Data access Layer, but I think analysis of the code below doesn't depend upon any specific ORM. What should be the single common place throughout the entire Data Access ...
Abhi's user avatar
  • 231
13 votes
4 answers
52k views

Test connection to database C#

I've created a small method to test the connection to a database: ...
user avatar
13 votes
4 answers
541 views

Lines, intersections and terrible unit tests

I needed Line and LineF for the next stage of a project I'm working on, so I developed them. I also needed to determine if two ...
Der Kommissar's user avatar
13 votes
5 answers
21k views

Disposing the Context in the Repository pattern

I have a question about the Repository pattern: ...
Bruno Klein's user avatar
13 votes
1 answer
5k views

Generic Converter framework

I find myself frequently converting between formats, so I have come up with the following conversion framework. The converter interface surfaces a method to convert from a source type to a target type....
Hawk's user avatar
  • 233
13 votes
1 answer
617 views

.NET 4.5 licensing subsystem using RSA-4096 strong name key, SHA256 signed XML, and assembly signature enforcing

Abstract For the past week I have been looking at taking advantage of the .NET 4.5 improvements to code signing and XML signing to produce a licensing subsystem I can use to license my own products. ...
Drunken Code Monkey's user avatar
12 votes
3 answers
16k views

Extension method replacing elements from an IEnumerable<T> collection

Today I needed a method to replace all 'x' values in a said collection. Since there is no such method by default in .NET I wrote my own: ...
Denis's user avatar
  • 8,448

1
2 3 4 5
25