Can I add an interface to a strongly typed DataSet in .NET?

I have a collection of strongly typed DataSets, each with two tables. One table is unique for each DataSet, but the second, "MetaData", has the same schema for each dataset.

At runtime, I determine which DataSet I want to use and populate the data table from the database accordingly.

Then I want to populate the MetaData table. This will be done the same for every DataSet, so I would like to use the same code. One obvious way to do this would be for each of the DataSets to implement an interface that will work.

The problem arises when I want to declare this interface (IMyInterface) for these datasets.

Each strongly typed DataSet comes with many files. The first and critical file is the MyDataSet.Designer.cs file ... this is the file that is automatically generated. There's a start line that reads:

public partial class MyDataSet : global::System.Data.DataSet

      

I could add my interface after that, but I have every reason to believe that it can / will be destroyed when this file is regenerated.

If I tell VS that I want to edit the code for the DataSet, it creates a new MyDataSet.cs file for me. But the declaration there looks like this:

partial class MyDataSet

      

If I tried to add an interface like this to it:

partial class MyDataSet : IMyInterface

      

it would look like I was trying to add a subclass.

What's the correct way to handle this? Modify the constructor file and make sure VS never regenerates it? Add both superclass and interface declaration to another file? Something else completely?

+2


source to share


1 answer


Wow. Never mind. Even though this was not found in a search, after re-querying this query (after entering this long question), I quickly found the answer.

It appears to be smart enough to be able to mix and match the two correctly, depending on whether it is inherited from a class or an interface to be implemented.

MSDN says:

For example, the following ads:



partial class Earth : Planet, IRotate { }
partial class Earth : IRevolve { }

      

are equivalent to:

class Earth : Planet, IRotate, IRevolve { }

      

+1


source







All Articles