473,830 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overloads Property Questions

I have a Collection Class That I am Creating ,

In This Collection Class I have a default Property Item.

My Problem is this I have about twenty different Criterias that can be used
as a value in searching for this item.

So i figured that i could use overloaded item property's, however it
seems that i may not have an overloaded property of the same value type

so what i have done is i made an enum that contains all of the different
criterias and then took in as variables for the property the criteria and the
value as an object

With the exception of the fact that the value variables can be any object
and so is
not explicitly stated, this seems to work fine.

My Question is , does anyone see any problems with this method that i have
mentioned that i have not noticed.

and also Does any one else no of a better way of solving this little dilema?

Thanks Again,
Really you guys are very Helpful In here!!!!

WStoreyII
Nov 21 '05 #1
3 3203
WStoreyII,
I'm not following specifically what you are doing. It sounds like you are
doing what the 3 of the overloaded DataRow.Item properties do. You pass an
Enum that acts as the "Version" (criteria), plus a value (what the criteria
matches on).

http://msdn.microsoft.com/library/de...ItemTopic5.asp

Overloads Public Default Readonly Property Item( _
ByVal columnName As String, _
ByVal version As DataRowVersion _
) As Object

Where DataRowVersion is an Enum.
The other option instead of an Enum might be an IComparer like object or
delegate that knows what property to look for the item in. Ala VB.NET 2005's
Predicate(Of T) Delegate and Array.Find method.

The Predicate Delegate is an address of a method that "defines a set of
criteria and determines whether the specified object meets those criteria".
http://msdn2.microsoft.com/library/bfcke1bz.aspx

While Array.Find scans the array Invoking the Predicate until a match is
found.

http://msdn2.microsoft.com/library/d9hy2xwa.aspx

A variation of the above would be to have the Predicate accept both the
value to look for & the value to check. Ala the Comparison(Of T) Delegate.

http://msdn2.microsoft.com/library/tfakywbh.aspx

Note the (Of T) above indicates a Generic, in VB.NET 2003 you cannot use the
Generic, however you can simply define the Delegates using Objects...

Public Delegate Comparison(ByVa l x As Object, ByVal y As Object) As
Integer

Public Delegate Predicate(ByVal x As Object) As Boolean

Hope this helps
Jay


"WStoreyII" <WS*******@disc ussions.microso ft.com> wrote in message
news:7C******** *************** ***********@mic rosoft.com...
I have a Collection Class That I am Creating ,

In This Collection Class I have a default Property Item.

My Problem is this I have about twenty different Criterias that can be
used
as a value in searching for this item.

So i figured that i could use overloaded item property's, however it
seems that i may not have an overloaded property of the same value type

so what i have done is i made an enum that contains all of the different
criterias and then took in as variables for the property the criteria and
the
value as an object

With the exception of the fact that the value variables can be any object
and so is
not explicitly stated, this seems to work fine.

My Question is , does anyone see any problems with this method that i have
mentioned that i have not noticed.

and also Does any one else no of a better way of solving this little
dilema?

Thanks Again,
Really you guys are very Helpful In here!!!!

WStoreyII

Nov 21 '05 #2
Jay,

You have lost me, let me retry to explain what i am doing.

I have a Collection Class Called Customers
this class has a few different fields that i would use as lookup fields for
the customer objects in its collection

List:
DateOfSale:Date
Item:String
Code:String
Name:String
Ect.

The Problem is that i Can not use overloaded Propertys Items because i cant
not have overloaded values of the same type and i have at least three strings

so what i did was created a enum that contains these values and then in the
item function they will pass the criteria and then the value that is to be
matched as an object.

I just wanted to know if there was a more efficent way of doing this.
WStorey II

Thanks Again.
"WStoreyII" wrote:
I have a Collection Class That I am Creating ,

In This Collection Class I have a default Property Item.

My Problem is this I have about twenty different Criterias that can be used
as a value in searching for this item.

So i figured that i could use overloaded item property's, however it
seems that i may not have an overloaded property of the same value type

so what i have done is i made an enum that contains all of the different
criterias and then took in as variables for the property the criteria and the
value as an object

With the exception of the fact that the value variables can be any object
and so is
not explicitly stated, this seems to work fine.

My Question is , does anyone see any problems with this method that i have
mentioned that i have not noticed.

and also Does any one else no of a better way of solving this little dilema?

Thanks Again,
Really you guys are very Helpful In here!!!!

WStoreyII

Nov 21 '05 #3
WStorey II,
What you did is fine, I gave an example of where the framework does the same
thing in some cases, the DataRow.Item property.
I was offering an alternative using Delegates, which is more work, but
significantly more flexibility.

Something like:

Option Strict On
Option Explicit On

Public Class WStoryII

Public Delegate Function Predicate(ByVal item As Customer, ByVal value
As Object) As Boolean

Public Class Customer

Public ReadOnly DateOfSale As Date
Public ReadOnly Item As String
Public ReadOnly Code As String
Public ReadOnly Name As String

Public Sub New(ByVal dateOfSale As Date, ByVal item As String, ByVal
code As String, ByVal name As String)
Me.DateOfSale = dateOfSale
Me.Item = item
Me.Code = code
Me.Name = name
End Sub

Public Overrides Function ToString() As String
Return String.Format(" Customer({0:d}, {1}, {2}, {3})",
DateOfSale, Item, Code, Name)
End Function

#Region " Predefined predicates "

Public Shared Function CompareName(ByV al item As Customer, ByVal
value As Object) As Boolean
Return item.Name = CStr(value)
End Function

Public Shared Function CompareDate(ByV al item As Customer, ByVal
value As Object) As Boolean
Return item.DateOfSale = CDate(value)
End Function

Public Shared Function CompareTodayFor Name(ByVal item As Customer,
ByVal value As Object) As Boolean
Return item.DateOfSale .Date = DateTime.Today AndAlso item.Name =
CStr(value)
End Function

#End Region

End Class

Public Class CustomerCollect ion
Inherits CollectionBase

Public Sub Add(ByVal dateOfSale As Date, ByVal item As String, ByVal
code As String, ByVal name As String)
Me.InnerList.Ad d(New Customer(dateOf Sale, item, code, name))
End Sub

Public Function Find(ByVal value As Object, ByVal predicate As
Predicate) As Customer
For Each item As Customer In Me.InnerList
If predicate.Invok e(item, value) Then
Return item
End If
Next
Return Nothing
End Function

End Class

Public Shared Sub Main()
Dim customers As New CustomerCollect ion
customers.Add(D ateTime.Today, "A1", "A", "Jay")
customers.Add(D ateTime.Today.A ddDays(-1), "B1", "B", "WStoryII")
customers.Add(D ateTime.Today.A ddDays(1), "C1", "C", "Sam")

Dim item As Customer

item = customers.Find( "WStoryII", AddressOf Customer.Compar eName)
Debug.WriteLine (item, "find name")

item = customers.Find( DateTime.Now, AddressOf Customer.Compar eDate)
Debug.WriteLine (item, "find now")

item = customers.Find( DateTime.Today, AddressOf
Customer.Compar eDate)
Debug.WriteLine (item, "find today")
End Sub

End Class
The advantage of using Delegates you can add functions that do comparisons
without modifying the Enum or the Find itself.

I used Find instead of Item, as I am searching for the item, rather then
indexing per se, you can just as easily made Find a Default Readonly
Property.

The CompareTodayFor Name is an example of a more complex predicate...

Hope this helps
Jay
"WStoreyII" <WS*******@disc ussions.microso ft.com> wrote in message
news:45******** *************** ***********@mic rosoft.com...
Jay,

You have lost me, let me retry to explain what i am doing.

I have a Collection Class Called Customers
this class has a few different fields that i would use as lookup fields
for
the customer objects in its collection

List:
DateOfSale:Date
Item:String
Code:String
Name:String
Ect.

The Problem is that i Can not use overloaded Propertys Items because i
cant
not have overloaded values of the same type and i have at least three
strings

so what i did was created a enum that contains these values and then in
the
item function they will pass the criteria and then the value that is to be
matched as an object.

I just wanted to know if there was a more efficent way of doing this.
WStorey II

Thanks Again.
"WStoreyII" wrote:
I have a Collection Class That I am Creating ,

In This Collection Class I have a default Property Item.

My Problem is this I have about twenty different Criterias that can be
used
as a value in searching for this item.

So i figured that i could use overloaded item property's, however it
seems that i may not have an overloaded property of the same value type

so what i have done is i made an enum that contains all of the different
criterias and then took in as variables for the property the criteria and
the
value as an object

With the exception of the fact that the value variables can be any object
and so is
not explicitly stated, this seems to work fine.

My Question is , does anyone see any problems with this method that i
have
mentioned that i have not noticed.

and also Does any one else no of a better way of solving this little
dilema?

Thanks Again,
Really you guys are very Helpful In here!!!!

WStoreyII

Nov 21 '05 #4

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

Similar topics

2
1274
by: valamas | last post by:
Hi All How can I recode the following so that I do not repeat my code? Public Overloads Sub SetNodeImageIndex(ByVal oNode As System.Windows.Forms.TreeNode, ByVal ImageIndex As String) oNode.ImageIndex = ImageIndex oNode.SelectedImageIndex = ImageIndex
59
3467
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
3
1279
by: Fabio Negri Cicotti [MCP] | last post by:
Hi all. How could I convert the VB.NET "Overloads" modifier to C#? Public Overloads Property DataSource() As Object End Property Grateful.
12
1753
by: Lee Silver | last post by:
In a base class I have the following 2 declarations: Overridable Sub Remove(ByVal wIndex As Integer) and Overridable Sub Remove(ByVal wValue As Object) In an immediately derived class I have the following declaration: Overloads Overrides Sub Remove(ByVal wIndex As Integer)
10
13799
by: Atif | last post by:
Hi I am here to solve a small confusion i have in "Overloads Overrides". "Overloading" says that the method's name should be same while no. of parameters and/or their datatypes should be changed either in the same class or inherited class. right? "Overriding" says that the method's signature should be same(name,no. of parameters and their datatypes) in the inherited class while implementation may change. right?
3
1753
by: Arthur Dent | last post by:
Hi all, Im just curious, what is the purpose of the keyword "Overloads" in VB nowadays? I understand conceptually what overloads are and what they do, but im a little puzzled, because if you declare two subs or properties or functions with the same name but different signatures, it seems to overload them without any problem anyway, so why
2
5787
by: Joseph Lu | last post by:
Hi, I have a multithread problem like the following lines, when I compile this code I caught a "error C2665", the error description is : none of the number1 overloads can convert parameter number2 from type 'type' //----------------------------- UINT ReadDatFile(int i_thread) { AfxMessageBox(i_thread); return 0; }
12
2397
by: André | last post by:
Hi, i'm learning working with classes. In class "classbase1", i defined an overridable function. In the class "subclass1", i defined the same function with 'Overrides'. In class "classbase2", i defined the same function and in the class "subclass2", i defined the same function with 'Overloads'. Result: i get the same output.
2
6590
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
In the class below, I inherit from Generic.Dictionary so I can override property Item. Item is not overridable, so I used Shadows, and it works as I want. It works equally well if I replace Shadows with Overloads. Question 1 - Which is preferred in a case like this, Shadows or Overloads. Question 2 - The Override clan (Overrides, Overridable, NotOverridable, MustOverride) seems to have lost some steam if I can effect an override on...
0
9781
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10769
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10477
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10197
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5615
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.