[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

remove repetitive code / pass property address into function

Posted on 2012-08-14
3
Medium Priority
?
287 Views
Last Modified: 2012-08-22
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
Comment
Question by:Ryan
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38293270
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
 
LVL 13

Accepted Solution

by:
Ryan earned 0 total points
ID: 38296677
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
 
LVL 13

Author Closing Comment

by:Ryan
ID: 38319673
No other solution was provided.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question