• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

remove repetitive code / pass property address into function

I have the following code in a n-tier app, which is repeated about 40 times in my using a different function in DA.Components, and I'm wondering if there's a cleaner way to do it.  

NewECNs is populated within the function call, and is normally empty, and may eventually get up to a count of 10.

Dim NewECNs As New List(Of String)
lblTypeLabel.Text = DA.Components.GetArrTypeLabelPN(arrFamily, _EffectiveDate, NewECNs)
For Each s As String In NewECNs
	ECNs.Add(New ECN(s, "Type Label"))
Next

Open in new window


My current thinking is if I could pass an address of the property ECN as list(of string), then I could remove all but the single function call, but I don't think I can do this? Any other ideas?
0
Ryan
Asked:
Ryan
  • 2
1 Solution
 
CodeCruiserCommented:
Not sure what you are doing there. Is the function call returning a string as well as populating a parameter?

Why not send the ECNs to the function call?

How about replacing

Dim NewECNs As New List(Of String)
lblTypeLabel.Text = DA.Components.GetArrTypeLabelPN(arrFamily, _EffectiveDate, NewECNs)
For Each s As String In NewECNs
      ECNs.Add(New ECN(s, "Type Label"))
Next

with

Dim NewECNs As New List(Of String)
lblTypeLabel.Text = DA.Components.GetArrTypeLabelPN(arrFamily, _EffectiveDate, NewECNs)
ECNs.AddRange(NewECNs.ToArray())
0
 
RyanProject Engineer, ElectricalAuthor Commented:
ECN is a Business Object (namespace), where as the DA.Components is a Data Accessor  (namespace).  DAs shouldn't see BOs in N-Tier, which is why I can't pass ECN into the function, and why I'm passing in a generic and then parsing the generic in my BO class.

Also notice I'm storing a label in this case "Type Label" with the ECN, not just a string.

Just being greedy and trying to get it all in 1 clean line.

I ended up passing a delegate sub to the DA.Components functions, which resides in the BO.

In DA Namespace
 
Public Shared Function GetArrTypeLabelPN(ByVal ArrType As String, ByVal EffectiveDate As Date, ByVal AddECN As AddECN) As String
     Return GetKeyValue("ArrTypeLabel" & ArrType, EffectiveDate, AddECN, "Type Label").ToString
End Function

Public Delegate Sub AddECN(ByVal ECN As String, ByVal ItemType As String)

Open in new window


In BO Namepace
retVal.Add(New LineItem(8, DA.Components.GetArrTypeLabel("ArrTypeLabel" & arrFamily, _EffectiveDate, AddressOf AddECN).ToString(), "1"))


Public Sub AddECN(ByVal ECN As String, ByVal ItemType As String)
	_ECNs.Add(New ECN(ECN, ItemType))
End Sub

Open in new window


Still seems a little bastardized to pass the address of a function in BO to DA.
0
 
RyanProject Engineer, ElectricalAuthor Commented:
No other solution was provided.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now