David Biehl

I have two base classes that I would like to inherit from with type parameters and constraints. The project they reside in builds just fine, and everything seems OK. Here are their definitions...

Code Snippet

namespace Abstracts {

public class RowWrapper<TDataRow>

where TDataRow : DataRow

public class TableWrapper<TRowWrapper>

: IBindingListView, IList where TRowWrapper : RowWrapper<DataRow>, new()

}

And then I have two classes that inherit from them in a different project...

Code Snippet

namespace Quotes {

public class QuoteLineItem : Abstracts.RowWrapper <QuotesDataSet.Quote_Line_ItemsRow>

public class QuoteLineItemsClass : Abstracts.TableWrapper<QuoteLineItem>

}

It should be noted that Quote_Line_ItemsRow inherits from DataRow, so there shouldn't be any problems.

When I try to build this project, I get the following error: "The type 'Quotes.Quote.QuoteLineItem must be convertible to 'Abstracts.RowWrapper<System.Data.DataRow>' in order to use it as a parameter 'TRowWrapper' in the generic type or method 'Abstracts.TableWrapper<TRowWrapper>'

I don't understand why I am getting this error. It doesn't appear that I'm going against any of the constraints.

Is there an interface that I need to implement to make this conversion I really don't understand why this is happening...

Any help would be appreciated. Thank you!



Re: Visual C# Language Type Parameters, Constraints, and Inheritance

David Biehl

I think I have it figured out, and figured I should post the solution in case anyone else is searching for this. I created another base class for the RowWrapper class without any type parameters and then the RowWrapper< > class inherited from that. In the table wrapper type constraints, I changed the constraing from the RowWrapper< > class to the RowWrapper class. That seems to do the trick, if any other issues come up related to this, I'll post another update. Here is the "working" class definitions...


Code Snippet

namespace Abstracts
{
public class RowWrapper

public class RowWrapper<TDataRow> : RowWrapper
where TDataRow : DataRow

public class TableWrapper<TRowWrapper>
: IBindingListView, IList<TRowWrapper> where TRowWrapper : RowWrapper, new()
}





Re: Visual C# Language Type Parameters, Constraints, and Inheritance

David Biehl

An even better solution!! Doesn't require the RowWrapper base class!!

Code Snippet

public class TableWrapper<TRowWrapper, TDataRow>

: BindingList<TRowWrapper>

where TRowWrapper : RowWrapper<TDataRow>, new()

where TDataRow : DataRow