What I want to achieve is something like this below, which Visual Studio complains about and I don't know how to achieve it:
public abstract class My_BaseControl<T> : T, IRightBasedUsability
where T : System.Web.UI.WebControls.WebControl
{
// Some methods that I want to have for all
//the extended asp.net controls along my application
//which implements IRightBasedUsability
}
Perhaps c# extension methods are in this case a way to solve your problem.
@see http://msdn.microsoft.com/en-us/library/bb383977.aspx
Eric De Carufel wrote some interesting articles about extension methods and how to manage their scope: http://blog.decarufel.net/2009/02/extension-methods-series-managing-scope.html
You can't inherit from a non-existent type at all, no; that's what you would be doing with the code you've shown.
The closest you can get would be to inherit from the class in your where T
clause. The effect would not be much different, anyway.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.