471,616 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

Hi,

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 3090
On Wed, 23 Apr 2008 16:45:01 -0700, DotNetNewbie <sn***********@yahoo.com>
wrote:
[...]
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
class.

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.

Pete

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Cool Guy | last post: by
8 posts views Thread by Cool Guy | last post: by
1 post views Thread by Tommaso Caldarola | last post: by
4 posts views Thread by Charles Churchill | last post: by
1 post views Thread by interX | last post: by
3 posts views Thread by webcliff | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.