473,394 Members | 1,811 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,394 software developers and data experts.

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 3193
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(ByVal x As Object, ByVal y As Object) As
Integer

Public Delegate Predicate(ByVal x As Object) As Boolean

Hope this helps
Jay


"WStoreyII" <WS*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.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(ByVal item As Customer, ByVal
value As Object) As Boolean
Return item.Name = CStr(value)
End Function

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

Public Shared Function CompareTodayForName(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 CustomerCollection
Inherits CollectionBase

Public Sub Add(ByVal dateOfSale As Date, ByVal item As String, ByVal
code As String, ByVal name As String)
Me.InnerList.Add(New Customer(dateOfSale, 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.Invoke(item, value) Then
Return item
End If
Next
Return Nothing
End Function

End Class

Public Shared Sub Main()
Dim customers As New CustomerCollection
customers.Add(DateTime.Today, "A1", "A", "Jay")
customers.Add(DateTime.Today.AddDays(-1), "B1", "B", "WStoryII")
customers.Add(DateTime.Today.AddDays(1), "C1", "C", "Sam")

Dim item As Customer

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

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

item = customers.Find(DateTime.Today, AddressOf
Customer.CompareDate)
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 CompareTodayForName is an example of a more complex predicate...

Hope this helps
Jay
"WStoreyII" <WS*******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.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
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) ...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
3
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
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...
10
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...
3
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...
2
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...
12
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...
2
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...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.