473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

MVC ViewPage<TViewData> How to Inheriting from a Generic Type?


In the source code for System.Web.MVC the generic class is defined as:

public class ViewPage<TViewData: ViewPage

I want to create my own custom ViewPage class, and inherit from the
generic type.

I tried:

public class MyViewPage : ViewPage<TViewDate>

I get a compile error:

Is it possible to do this??
Jun 27 '08 #1
1 3151
On Wed, 23 Apr 2008 16:45:01 -0700, DotNetNewbie <sn***********@yahoo.com>
I want to create my own custom ViewPage class, and inherit from the
generic type.

I tried:

public class MyViewPage : ViewPage<TViewDate>

I get a compile error:

Is it possible to do this??
First you need to decide what "this" is. But once you've done that, yes.

One alternative is to declare your class like this:

public class MyViewPage<TViewData: ViewPage<TViewData>

Then you would need to provide the generic type parameter when using your

If you expect your class to only ever be used with one type as the type
parameter to ViewPage<TViewData>, then just provide that type parameter
when you declare your class, like this:

public class MyViewPage : ViewPage<MyViewDataClass>

where "MyViewDataClass" is whatever is your actual type that you want to
use with the generic class.


Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Cool Guy | last post by:
I don't understand the third paragraph under the heading 'Generic type instantiations' on <http://msdn.microsoft.com/vcsharp/2005/overview/language/generics/>: | The .NET Common Language Runtime...
by: Cool Guy | last post by:
From <http://msdn2.microsoft.com/en-us/library/f4a6ta2h(en-US,VS.80).aspx>: | As with the previous use of the Stack<T> class created with the Order | type, another instance of the specialized...
by: Tommaso Caldarola | last post by:
delegate void SomeDelegate<T>() where T : BaseClass; my_event(object sender, myEventArgs e) { //e.Tag object is SomeDelegate<DerivedClass> SomeDelegate<BaseClass> del =...
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my...
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
by: Néstor Sánchez A. | last post by:
Hi, is there a way, maybe using reflection, to use a generic class passing the type parameter dynamicly (not kwnowing the exact type at compile time)? I tried the next example, but doesn't work: ...
by: interX | last post by:
Hi I'm new in VC++ and have a question to generics. I have a generic class, which contains an array of the generic type. This array I can pin and then I would like to get an unmanaged pointer to...
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
by: webcliff | last post by:
Please help me to look at the following code: -------------start---------- using System; using System.Collections.Generic; public class GenType { }
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.