11
votes
2answers
424 views

Is this C# 'hack' a bad idea?

As C# doesn't have generic specialisation like C++ template specialisation and I wanted a way to be able to do it, I came up with a little hack that goes a bit like this: ...
10
votes
3answers
206 views

Cast inside the method or let the client code cast, which one is better?

I have two choices of implementing a method, the first one is a generic type where the client code does not have to cast ...
9
votes
3answers
317 views

Recursive Fibonacci with Generic delegates

Here is fast recursive fibonacci like for loop. How it be more readable and is possible remove TArg's ? ...
8
votes
1answer
524 views

using <T> in generic delegates?

Here is my problem. Do I need to give a new identifier to each delegate I write of the following delegate type? like so: or could i use one delegate that accounts for any Datatype I need to use so i ...
8
votes
1answer
186 views

Cache wrapper - Generics vs Dynamic

I've implemented a common wrapper pattern I've seen for the .NET cache class using generics as follows: ...
7
votes
2answers
202 views

Game passive skill system

I'm trying to create some easily accessible database of different skills. General idea is that every skill should do something different and be able to act on different things (ex. one skill which ...
7
votes
2answers
272 views

Synced/Atomic access

Forward I would love any comments you have, any ideas, any flaws you can find, and any suggestions you might have regarding the code below. If this is similar to other implementations, I would love ...
6
votes
2answers
892 views

Empty Interface usage - is this a code smell?

I've recently made a set of interfaces/classes to work with converting a spreadsheet into an object but I utilise an empty interface in my design: So first off I have my interface which defines what ...
6
votes
2answers
284 views

Online-Offline Class Manager

Router is a generic class that manage multiple contracts that. It is able to find out wheter it's an online or offline situation, on the very moment when an operation is being made. There's a really ...
6
votes
1answer
336 views

PriorityQueue<T> Implementation — Flaws, Thoughts, General Feedback

I have been looking desperately for some more experienced .NET (C#) software developers to take a look at my code, and provide me with some good ol' honest feedback and/or criticism about it. It only ...
6
votes
2answers
90 views

Abstract Factory Experiment

While I should probably be using Dependency Injection via Ninject or a similar project, I have been attempting to implement an abstract factory design that would provide me with the following easy to ...
6
votes
2answers
369 views

Generic wrapper for equality and hash implementation: Is there a way I can make it more efficient?

I was writing an answer in another thread and came across this challenge. I'm trying to have a generic class so that I can delegate the routine (and tiring) Equals ...
6
votes
2answers
636 views

Generic Calculator and Generic Number

.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile: ...
5
votes
2answers
205 views

Static Data Helper for an Oracle Backend

What I would like to do is have a method call like: ...
5
votes
2answers
596 views

Generic Task Blocking Queue

A generic blocking queue has the following properties: It is thread-safe. It allows queuing and de-queuing of items of a certain type (T). If a de-queue operation is performed and the ...
5
votes
1answer
61 views

Message Based Communication Design

I'm trying to design an API.NET for some communication purposes with Testing Equipment and I cannot figure out a proper way for designing the architecture. Basically, we have different (physical) ...
5
votes
1answer
42 views

Having children call parent's public events with data generated from a protected event

I don't know that my title describes the code I want reviewed. Hopefully the code is explanatory. I have an abstract parent class with two children. The parent listens to some hardware notifications ...
5
votes
1answer
88 views

Is there a simpler way to create this Inheritance structure for overriding an internal Generic Type?

I have some code below which is designed for the following purposes: Implement a cache structure which stores cached elements, as well as a method for reloading those elements. Ensure the new ...
5
votes
2answers
762 views

Generic Wrapper for a Task-based API

I've written a piece of an ugly code. The idea was to provide a clear-looking, type-inferring framework to test a task-based API (it's for integration testing, and test methods should be as clear as ...
4
votes
3answers
130 views

Refactor C# Linq code to reduce duplication

I currently have the below code: ...
4
votes
1answer
108 views

Generic 'temporary instance' class

I've been reading about WeakPointer and WeakPointer<T> today, and it looks very useful. Rather than just using it as-is ...
3
votes
3answers
256 views

Client trip type contracts

I want to make this code generic, so that I could remove if/else and recursive for loops. ...
3
votes
1answer
75 views

Is this a good way to deal with this tricky generic situation?

I have a project which should be thought of split into two layers: an IO layer which consists of sensors (input) and effectors (output), and a core layer which contains logic for determining which ...
3
votes
1answer
102 views

Genericizing PropertyValues

This should be the last iteration for this code. Question 1 Does this approach make sense or am I heading down the wrong path? Question 2 The only thing I can see to make this better is to ...
3
votes
3answers
972 views

ReadOnlyCollection - my alternative to .NET one

I wanted something more flexible than System.Collections.ObjectModel.ReadOnlyCollection. The goal was: consuming classes should only see what I want to show them, not whole underlying collection. For ...
3
votes
1answer
94 views

Session state wrapper, extending an existing application

I'm adding additional functionality to an existing MVC .net application, and to help prevent or at least reduce repeated reads to the dB I'm dumping a few custom entities in session. I'm limiting what ...
3
votes
1answer
210 views

Repository Pattern Review

I have following code for a library management system. Is the following code a proper implementation of the Repository Pattern? How can I adapt this code to use generics? Should I let ...
3
votes
1answer
194 views

How is the design of this Singleton implementation

I did this as an exercise just to practive/improve using generics. Independent of how useful this implementation of a Singleton is, how is my coding in terms of using generics and any other aspect of ...
3
votes
1answer
45 views

Refactoring my windowsFormApp code

I have around 150 lines of code that I managed to optimize. But, because my two methods and the six if-statements almost are identical, could there be room for improvement? Maybe it could be done ...
3
votes
2answers
2k views

Is there a better way of defining generic entity classes?

I have some entities in use in my project, and to make things easier, I would like to have the type of the key for that entity defined via a generic. E.g.: ...
3
votes
2answers
106 views
3
votes
0answers
30 views

Many interfaces and lots of inheritance vs few interfaces and less inheritance?

I have a Visual Studio Solution which has a bunch of Projects in it. One of these projects is called "Services" and is basically the junction point between all remaining projects. When I built it ...
2
votes
1answer
3k views

Polling loop to run in a background thread

I came up with the idea of a small utility class that will poll some delegate until the response received meets some condition, upon which it will notify the main thread which can take the appropriate ...
2
votes
1answer
144 views

Delegate that selects a writable property on a generic

In the following contrived example, I have a collection of PropertyManagers that each contains selector and assigner delegates to read from and write to a property ...
2
votes
1answer
100 views

VARIANT structure deserialization code organization

In my project i work with COM object via System.Reflection. COM object returns pointer on structure VARIANT, that i cast as ...
2
votes
1answer
156 views

How to remove duplicated code? AOP and Generics are Ok

I have figures - TriangleItem and CircleItem: ...
2
votes
2answers
669 views

Sequential Execution: Orchestrator Pattern

I built a code piece that makes it easy to execute a set of sequential operations, that might depend on the same parameter value (passed across the execution) or might need a particular parameter. ...
2
votes
2answers
86 views

Generically typed interface

I came across the following code in our code base: ...
2
votes
1answer
2k views

Review of a generic request handler class (RestSharp)

I wrote a class that uses RestSharp to access Rest and HTTP API web services. I tested it and it works however I was wondering if any changes could be made to it to make it better. ...
2
votes
1answer
143 views

Generics: Is this improper use?

I have a class library in which I'm using generics as below. I'm not sure if it's an improper use or not. So aside from the fact that it works and everything "depends", id like some specific critique ...
1
vote
2answers
97 views

Covariance in generic collections

I have a some classes and interface ...
1
vote
3answers
153 views

Can I somehow tidy up this (overuse?) of generics?

I'm building a generic flat file reader which looks something like this. ...
1
vote
1answer
206 views

Generic, thread-safe MemoryCache manager for C#

Using this question as a base, and using some of the advice in the answers, I wanted to build out something that would be generic, thread-safe, and easy to use for at least one current and several ...
1
vote
1answer
261 views

A genric extension method to filter Linq-EF queries

I have various types of EF entities, all of them have a navigation property called "Employee". When generating reports the user will have the option to filter the report according to the different ...
1
vote
1answer
127 views

Improving my code to be more generic

This is one of a classes (that sends email base on object type to AM (Role)) that is executed by a engine. I have also commands like SendEmailToAOCommand that send ...
1
vote
0answers
39 views

Feedback for a mostly auto-generated generic data layer

I'm trying to make a reusable data layer that is mostly generated from a database via T4 templates. On top of this data layer, I'd like to have WebAPI endpoints for each repository, with most of the ...
0
votes
1answer
150 views

Refactoring code into a generic method [closed]

I have a reoccuring code block in my EntityFramework backed repository which I would like to genericise somehow and call as a method, so reuse the code rather than repeat it. The current code block ...
0
votes
0answers
329 views

Binding and iterating a database table to a List<T> in C#

I would like to iterate through the records of a database table using a C# List of my custom class. Is this the most performant way to handle this? (Simplified for ...