Overloading the = in c#

S

shalafi

Here's the issue.. I wrote up the middle tier as a model of the objects to
my satisfaction. but the result is that instead of asp.net pages using
datasets to construct the gui, they are dealing with User[], Article[],
Category[]... etc.

My first thought was to overload the = operator so i can do

DataSet x = theUsers;

where the = would do the conversion and i can take the dataset to slap into
a datagrid.

I have thought up some ways, but just curious what everyone thinks is the
best way to deal with this. I cant use a normal function because it's an
array. aka .toDataSet() isnt gonna cut it unless i do
User.toDataSet(theUsers);
 
D

David Browne

shalafi said:
Here's the issue.. I wrote up the middle tier as a model of the objects to
my satisfaction. but the result is that instead of asp.net pages using
datasets to construct the gui, they are dealing with User[], Article[],
Category[]... etc.

My first thought was to overload the = operator so i can do

DataSet x = theUsers;

where the = would do the conversion and i can take the dataset to slap into
a datagrid.

I have thought up some ways, but just curious what everyone thinks is the
best way to deal with this. I cant use a normal function because it's an
array. aka .toDataSet() isnt gonna cut it unless i do
User.toDataSet(theUsers);

There's a whole databinding framework you can use. You need an adapter for
your business object to allow the UI to databind it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp
http://aspalliance.com/articleViewer.aspx?aId=77
http://www.codeproject.com/aspnet/OODatabinding.asp

David
 
S

shalafi

thanks major!...

I've done quite a bit of OOP... java and c++. But that always takes a
backseat to learning the class libraries available. this will give me a big
boost in the right direction.


David Browne said:
shalafi said:
Here's the issue.. I wrote up the middle tier as a model of the objects to
my satisfaction. but the result is that instead of asp.net pages using
datasets to construct the gui, they are dealing with User[], Article[],
Category[]... etc.

My first thought was to overload the = operator so i can do

DataSet x = theUsers;

where the = would do the conversion and i can take the dataset to slap into
a datagrid.

I have thought up some ways, but just curious what everyone thinks is the
best way to deal with this. I cant use a normal function because it's an
array. aka .toDataSet() isnt gonna cut it unless i do
User.toDataSet(theUsers);

There's a whole databinding framework you can use. You need an adapter for
your business object to allow the UI to databind it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp
http://aspalliance.com/articleViewer.aspx?aId=77
http://www.codeproject.com/aspnet/OODatabinding.asp

David
 
N

Nick

You can call arrays the same way that you call Datasets in ASP.Net
Pages. Say you have an DataTalble with a field of "MyProperty". Then
you call it in the page like <%# DataBinder.Eval(Container.DataItem,
"MyProperty") %>, but if you are using an actual array with a object
that has a property called my property you can do <%#
DataBinder.Eval(Contaier, "MyProperty") %> and it will work fine.

http://msdn.microsoft.com/library/d...frlrfsystemwebuidatabinderclassevaltopic1.asp

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top