Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can C# generics have a specific base type?

Tags:

c#

generics

Is it possible for a generic interface's type to be based on a specific parent class?

For example:

public interface IGenericFace<T : BaseClass> { } 

Obviously the above code doesn't work but if it did, what I'm trying to tell the compiler is that T must be a sub-class of BaseClass. Can that be done, are there plans for it, etc.?

I think it would be useful in terms of a specific project, making sure a generic interface/class isn't used with unintended type(s) at compile time. Or also to sort of self-document: show what kind of type is intended.

like image 938
Neil C. Obremski Avatar asked Oct 23 '08 17:10

Neil C. Obremski


People also ask

Is Can-C good for your eyes?

Benefits of Can-C Eye Drops:Can assist to lower the intraocular pressure associated with glaucoma. Are also beneficial for contact lens disorders. Have also been shown to help those suffering from presbyopia. Can be used to treat corneal disorders.

Is Can-C good for dogs?

SAFE FOR HUMANS AND DOGS - Can-C is the first and only patented NAC eye drop that uses the exact formula proven effective in both animal and human trials, offering a non-invasive alternative to cataract surgery. EVERY BLINK HYDRATES and lubricates the eye and cornea.

Does Can-C work for cataracts?

By managing cataracts with Can-C, some patients may be able to avoid cataract surgery and keep their own natural lens. Cataract surgery is an in-office or outpatient procedure done without the need for general anesthetic. The diseased lens is removed and replaced.

Can-C NAC?

The main ingredient of Can-C™ NAC eye drops is N-acetylcarnosine (NAC), a special analogue of di-peptide carnosine, a naturally occurring anti-oxidant nutrient. NAC is extremely effective at 'mopping up' free radicals, which accelerate aging in the body, including the growth of cataracts.


1 Answers

public interface IGenericFace<T> where T : SomeBaseClass 
like image 59
Ryan Lundy Avatar answered Sep 23 '22 22:09

Ryan Lundy