473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Overloaded methods

A little embarrassing but,

Public Sub MySub(ByVal row as MyTable1Row)
....
End Sub

Public Sub MySub(ByVal row as MyTable2Row)
....
End Sub
How do I get the following to work without the Select...Case block and the
Ctypes?

Public Sub DoSomething(ByVal row as Datarow)
Select Case row.GetType.Name
Case "MyTable1Row"
MySub(Ctype(row,MyTable1Row))
Case "MyTable2Row"
MySub(Ctype(row,MyTable2Row))
End Select
....
End Sub

I was hoping for something more like this

Public Sub DoSomething(ByVal row as DataRow)
MySub(Ctype(row,row.GetType)
....
End Sub

Thanks,

Pat
--
Pat
Nov 21 '05 #1
4 1223

I think the usual way to do this might be to have the "MySub" method as
overridden members of the MyTable1Row and MyTable2Row classes, so that the
behaviour of "MySub" is encapsulated in the class itself; like this:

public class MyTableRow
Inherits DataRow

Public Overridable Sub MySub ()
End Sub

End Class

public class MyTable1Row
Inherits MyTableRow

Public Overrides Sub MySub ()
' Perform some action
End Sub
End Class

Public Class MyTable2Row
Inherits MyTableRow

Public Overrides Sub MySub ()
' Perform some action
End Sub
End Class
..................
..................
Public Sub Dosomething ( byval theRow as MyTableRow )
theRow.MySub ()
End Sub

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
A little embarrassing but,

Public Sub MySub(ByVal row as MyTable1Row)
...
End Sub

Public Sub MySub(ByVal row as MyTable2Row)
...
End Sub
How do I get the following to work without the Select...Case block and the
Ctypes?

Public Sub DoSomething(ByVal row as Datarow)
Select Case row.GetType.Name
Case "MyTable1Row"
MySub(Ctype(row,MyTable1Row))
Case "MyTable2Row"
MySub(Ctype(row,MyTable2Row))
End Select
...
End Sub

I was hoping for something more like this

Public Sub DoSomething(ByVal row as DataRow)
MySub(Ctype(row,row.GetType)
...
End Sub

Thanks,

Pat
--
Pat

Nov 21 '05 #2
Excellent idea. The problem (I think) is then 2 weeks later when I tweak the
structure of the dataset VisualStudio overwrites all my custom coding in the
autogenerated classes. Or maybe there is a way to avoid this...?

Thanks,

Pat

"Robin Tucker" wrote:

I think the usual way to do this might be to have the "MySub" method as
overridden members of the MyTable1Row and MyTable2Row classes, so that the
behaviour of "MySub" is encapsulated in the class itself; like this:

public class MyTableRow
Inherits DataRow

Public Overridable Sub MySub ()
End Sub

End Class

public class MyTable1Row
Inherits MyTableRow

Public Overrides Sub MySub ()
' Perform some action
End Sub
End Class

Public Class MyTable2Row
Inherits MyTableRow

Public Overrides Sub MySub ()
' Perform some action
End Sub
End Class
..................
..................
Public Sub Dosomething ( byval theRow as MyTableRow )
theRow.MySub ()
End Sub

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
A little embarrassing but,

Public Sub MySub(ByVal row as MyTable1Row)
...
End Sub

Public Sub MySub(ByVal row as MyTable2Row)
...
End Sub
How do I get the following to work without the Select...Case block and the
Ctypes?

Public Sub DoSomething(ByVal row as Datarow)
Select Case row.GetType.Name
Case "MyTable1Row"
MySub(Ctype(row,MyTable1Row))
Case "MyTable2Row"
MySub(Ctype(row,MyTable2Row))
End Select
...
End Sub

I was hoping for something more like this

Public Sub DoSomething(ByVal row as DataRow)
MySub(Ctype(row,row.GetType)
...
End Sub

Thanks,

Pat
--
Pat


Nov 21 '05 #3
This I can't answer as I have never used these autogenerated classes.
Perhaps you could do an experiment and report back to the group ;)

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Excellent idea. The problem (I think) is then 2 weeks later when I tweak
the
structure of the dataset VisualStudio overwrites all my custom coding in
the
autogenerated classes. Or maybe there is a way to avoid this...?

Thanks,

Pat

"Robin Tucker" wrote:

I think the usual way to do this might be to have the "MySub" method as
overridden members of the MyTable1Row and MyTable2Row classes, so that
the
behaviour of "MySub" is encapsulated in the class itself; like this:

public class MyTableRow
Inherits DataRow

Public Overridable Sub MySub ()
End Sub

End Class

public class MyTable1Row
Inherits MyTableRow

Public Overrides Sub MySub ()
' Perform some action
End Sub
End Class

Public Class MyTable2Row
Inherits MyTableRow

Public Overrides Sub MySub ()
' Perform some action
End Sub
End Class
..................
..................
Public Sub Dosomething ( byval theRow as MyTableRow )
theRow.MySub ()
End Sub

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
>A little embarrassing but,
>
> Public Sub MySub(ByVal row as MyTable1Row)
> ...
> End Sub
>
> Public Sub MySub(ByVal row as MyTable2Row)
> ...
> End Sub
>
>
> How do I get the following to work without the Select...Case block and
> the
> Ctypes?
>
> Public Sub DoSomething(ByVal row as Datarow)
> Select Case row.GetType.Name
> Case "MyTable1Row"
> MySub(Ctype(row,MyTable1Row))
> Case "MyTable2Row"
> MySub(Ctype(row,MyTable2Row))
> End Select
> ...
> End Sub
>
> I was hoping for something more like this
>
> Public Sub DoSomething(ByVal row as DataRow)
> MySub(Ctype(row,row.GetType)
> ...
> End Sub
>
> Thanks,
>
> Pat
> --
> Pat


Nov 21 '05 #4
"pmcguire" <pm******@discussions.microsoft.com> schrieb
A little embarrassing but,

Public Sub MySub(ByVal row as MyTable1Row)
...
End Sub

Public Sub MySub(ByVal row as MyTable2Row)
...
End Sub
How do I get the following to work without the Select...Case block
and the Ctypes?

Public Sub DoSomething(ByVal row as Datarow)
Select Case row.GetType.Name
Case "MyTable1Row"
MySub(Ctype(row,MyTable1Row))
Case "MyTable2Row"
MySub(Ctype(row,MyTable2Row))
End Select
...
End Sub
Use "If TypeOf .. Is" instead of comparing strings to avoid misspelled type
names. The compiler can't recognize them.
I was hoping for something more like this

Public Sub DoSomething(ByVal row as DataRow)
MySub(Ctype(row,row.GetType)
...
End Sub

CType requires a type expression, not a System.Type object because the type
and the call must be resolved at compile time. I don't see a way around
CType/Directcast.
Armin

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrea_gavana | last post by:
Hello NG, I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython implementation. In the C++ source code, a unique class is initialized with 2 different methods (???)....
3
by: PengYu.UT | last post by:
The following program shows that virtual function can not be overloaded. Could you tell me the reasons from the C++ compiler point of view? Thanks! Peng #include <iostream>
10
by: john bailo | last post by:
Can a web method be overloaded? To support varying numbers of input parameters?
3
by: cybertof | last post by:
Hello, Is it possible in C# to have 2 overloaded functions with - same names - same parameters - different return type values If no, is it possible in another language ?
8
by: Brian Hampson | last post by:
I'm new to this delegate thing, and I need to use it to do UI updates from a backgroundworker thread. I have a method with overloaded signatures of: void MyMethod(string MyString); void...
0
by: Mikkel Blanné | last post by:
I haven't been able to find any references to using this combination of technologies (remoting + generic methods + method overloading). I don't think the problem has to do with C#, but I couldn't...
1
by: prakash.mirji | last post by:
Hello, I am trying to compile C++ code which uses rogue wave 9.0 classes on RHEL 4.0. I use gnu g++ compiler to compile the code. Compiler is not able to match the right type of parameters to...
2
by: t | last post by:
If a method of a class is overloaded, and one of these methods is inlined, do all of them have to be inlined? I tried writing and filling out an example from Lippman's C++ book, 4th ed., and...
6
by: RobertEstelle | last post by:
Hello, I've been banging my head against this problem for a couple hours now to no avail. I'm trying to make a descendant of a class that has overloaded methods with variable argument lists....
9
by: Lawrence Krubner | last post by:
Possibly a dumb question but is type hinting allowed with overloaded methods? Can one class have these two methods? public function doSelect(Criteria $c) { // some code here } public...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.