Here's the generic class I'm working with:
public interface IRepository<T> where T : EntityObject
{
RepositoryInstructionResult Add(T item);
RepositoryInstructionResult Update(T item);
RepositoryInstructionResult Delete(T item);
}
public class Repository<T> : IRepository<T> where T : EntityObject
{
RepositoryInstructionResult Add(T item)
{ //implementation}
RepositoryInstructionResult Update(T item);
{ //implementation}
RepositoryInstructionResult Delete(T item);
{ //implementation}
}
Now I'm looking to occasionally alter the behavior of the methods when t : a specific type. Is something like the following possible? This particular attempt gives an error (Error 5: Partial declarations of 'Repository' must have the same type parameter names in the same order).
public class Repository<Bar> //where Bar : EntityObject
{
RepositoryInstructionResult Add(Bar item)
{ //different implementation to Repository<T>.Add() }
//other methods inherit from Repository<T>
}
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
The main difference between C and C++ is that C is a procedural programming language that does not support classes and objects. On the other hand, C++ is an extension of C programming with object-oriented programming (OOP) support.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
public class BarRepository : Repository<Bar>
{
RepositoryInstructionResult Add(Bar item)
{ //different implementation to Repository<T>.Add() }
//other methods inherit from Repository<T>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With