How to properly utilize generics to practice interface based programming for decoupling parts of the system?
I’m trying to create a hypothetical system with restaurants, products, options and product IDs.
Generics and possibly circular dependencies
public abstract class Display { } public abstract class Display<TLogic> : Display where TLogic : Logic<Display<TLogic>> { private TLogic logic; protected Display(){ } public void SetLogic(TLogic log)=> logic = log; } public abstract class Logic { } public abstract class Logic<TDisplay> : Logic where TDisplay : Display<Logic<TDisplay>>, new() { private TDisplay display; public void OnStart() […]
Using an abstract class with generic method as a property in another class
I have an abstract class
like this:
“Cannot implicitly convert type” error only when generic is instantiated with an interface
Why does the compiler ask for an explicit cast for a generic – when an implicit one has been defined – only when the generic has been instantiated with an interface?
Adding 2 different generic types that implement INumber
I am making a Matrix class in C#, and would like for it to be able to include any type that implements the INumber interface. I am unsure of how to be able to implement addition for matrices with different generic types e.g. Matrix<int>
and Matrix<float>
.
Adding 2 different generic types that implement INumber
I am making a Matrix class in C#, and would like for it to be able to include any type that implements the INumber interface. I am unsure of how to be able to implement addition for matrices with different generic types e.g. Matrix<int>
and Matrix<float>
.
How to simulate non-type template parameters in C# for generic classes for compile time type safety?
Is there a way to treat integers eg. 3
and 5
as their own types with an additional property being the value they represent? Specifically I want Modulo<3>
to be different to Modulo<5>
to prevent them being used together in an operation that operates on multiple Modulo<T>
s.
C generics using void * vs. macros
As I understand it, the standard way to implement generic data types in C is with void pointers. However, an alternate approach would be to use macros. Here’s an example implementation of a generic “Option” type using macros:
omitting generics in extension methods
Following is the starting code structure
How to pass in a generic list to a method in c#
I have a Mediator class with a register pipeline method that takes a message type, a pipeline filter type, and a message handler type.