I am trying to find the name of a generic usage pattern in C #, and I don't know a better resource than a stack overflow!
What I'm doing is creating base base classes that the derived class is directly passed to - I looked and looked for examples of this or the name of the template, and I was hoping one of the great members of this community could help me.
I wrote about how it works at http://www.mobiusbay.com/home/alittlesomethingimcallingcascadinggenerics , but if you prefer not to read it, an example of this follows
public abstract class IndexedMemberBase<TDerivedClass> : IDisposable where TDerivedClass : IndexedMemberBase<TDerivedClass> {
That a base class and a derived class can be incredibly simple - for example:
public class IndexMember : IndexedMemberBase<IndexMember> {
This piece of code throws a pointer to each instance of the dervied class into a static collection for general use - the collection is different for each derived class, so you will not have conflicts with the existing one statically in the database. I believe that this is very useful in my projects, and I hope that someone else will find it useful.
It is important to note that the derived class passes in a common signature to the base class.
If anyone has seen this template in use or knows a name for it, I would really like to see some examples, or at least call it the correct name! At the moment, I call it recursive generics, as it seems to fit, but I'm sure the best name is there!
Many thanks for your help!
Adam
source share