3

I was searching for reusable Grid for MVC .Net. I found one open source Grid.

In the code I found a pretty interesting class declaration which I didn't understand . Can anybody tell me a detailed description of class declaration below:

public class Grid<TEntity, TSearchForm> : IGrid where  TSearchForm : SearchForm, new()
{
}

Also how do I create an instance of this class?

1
  • What part of this do you not understand?
    – Oded
    Commented Nov 29, 2012 at 13:24

3 Answers 3

6
  • Grid class implements IGrids interface.
  • TSearchFormType must be of type SearchForm (by derivation)
  • TSeachForm must have a constructor without parameters
6

This is generic class inherited from IGrid with two parameters: TEntity, TSearchForm.

Also there is a constraint on type of TSearchForm:

  1. it must be of type SearchForm or below it in hierarchy (able to cast to SearchForm implicitly)

  2. TSearchForm must have public parameterless constructor.

More info:

where (generic type constraint new Constraint

1
5

The class is a generic class, it implements IGrid.

The two generic type parameters are TEntity and TSearchForm.

TSearchForm is constrained to be SearchForm or a type that inherits from SearchForm and that it has a default constructor.

Suggested reading:

1
  • 1
    @RahulRajput - It is not a constructor. It is a class declaration.
    – Oded
    Commented Nov 29, 2012 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.