?
Solved

C#

Posted on 2012-04-09
5
Medium Priority
?
238 Views
Last Modified: 2012-05-31
Hi Experts,

I have methods of same kind, which accept same type of parameters but inside the function it should get different html string and assign value.

Like this I have 16 fundtions, so I need to call the each and every function 16 times as given below,

Is there is any other concept, using which, I can have single line of statement to call the 16 methods.
(I mean, dynamically call 16 methods by using less number of lines).

I thought of delegate, but i don't think so, i can go for it, I need mulicaste delegate, but all my methods retung string.

Please suggesst.
//The below will repeat 16 times....want to avoid that..
string LstrPriorVP1 = string.Empty;
string LstrPriorVP2 = string.Empty;

string LstrCurrentVP1 = string.Empty;
string LstrCurrentVP2 = string.Empty;

LstrCurrentVP1 = BuildVP1Str(LobjCurrentVehiclePremiumsList, LstrCurrentVP1, "Current");
LstrPriorVP1 = BuildVP1Str(LobjPriorVehiclePremiumsList, LstrPriorVP1, "Prior");
PstrVP1 = LstrCurrentVP1 + LstrPriorVP1;

LstrCurrentVP2 = BuildVP2Str(LobjCurrentVehiclePremiumsList, LstrCurrentVP2, "Current");
LstrPriorVP2 = BuildVP2Str(LobjPriorVehiclePremiumsList, LstrPriorVP2, "Prior");                
PstrVP2 = LstrCurrentVP2 + LstrPriorVP2;

 private string BuildVP1Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
        {
            int LiVehicleInfoResultID = 0;
            foreach (VehiclePremiums LobjVP in PobjVPList)
            {
               
                string LstrVP = HTMLResource.VehiclePremiumSection1;              
               
                LstrVP = LstrVP.Replace("VP_PolicyInfoTypeValue", PstrPolicyInfoType);
               
                LstrVP = LstrVP.Replace("VP_LiabilityPremiumValue", LobjVP.LiabilityPremium.ToString());
                .....

                PstrVP = PstrVP + LstrVP;
            }
            return PstrVP;
        }

   private string BuildVP2Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
        {

            foreach (VehiclePremiums LobjVP in PobjVPList)
            {
             
                string LstrVP = HTMLResource.VehiclePremiumSection2;
             
                LstrVP = LstrVP.Replace("VP_PolicyInfoTypeValue", PstrPolicyInfoType);

                LstrVP = LstrVP.Replace("VP_ComprehensivePremiumValue", LobjVP.ComprehensivePremium.ToString());

                ...........

                PstrVP = PstrVP + LstrVP;
            }
            return PstrVP;
        }


Please help..................
0
Comment
Question by:RameshLathu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 1500 total points
ID: 37823904
i changed the function to get the vehiclePremiumSection as parameter cause it differ for each one, also the replace string of "Current" and "Prior" is done at the same run inside the function one after the other and returns a concatenated string result.

   private string BuildVPStr(ArrayList PobjVPList, string vehiclePremiumSection)
        {
String result=String.Empty;
  foreach (VehiclePremiums LobjVP in PobjVPList)
            {
            result+=vehiclePremiumSection.Replace("VP_PolicyInfoTypeValue", "Current").Replace("VP_ComprehensivePremiumValue", LobjVP.ComprehensivePremium.ToString());


            }

  foreach (VehiclePremiums LobjVP in PobjVPList)
            {
            result+=vehiclePremiumSection.Replace("VP_PolicyInfoTypeValue", "Prior").Replace("VP_ComprehensivePremiumValue", LobjVP.ComprehensivePremium.ToString());


            }
            return result;
       }

Open in new window


instead of

LstrCurrentVP1 = BuildVP1Str(LobjCurrentVehiclePremiumsList, LstrCurrentVP1, "Current");
LstrPriorVP1 = BuildVP1Str(LobjPriorVehiclePremiumsList, LstrPriorVP1, "Prior");
PstrVP1 = LstrCurrentVP1 + LstrPriorVP1;

LstrCurrentVP2 = BuildVP2Str(LobjCurrentVehiclePremiumsList, LstrCurrentVP2, "Current");
LstrPriorVP2 = BuildVP2Str(LobjPriorVehiclePremiumsList, LstrPriorVP2, "Prior");                
PstrVP2 = LstrCurrentVP2 + LstrPriorVP2;

using the following approach u still need to call 16 times to this function, each time with different vehiclePremiumSection:
string vp1 = BuildVPStr(LobjCurrentVehiclePremiumsList, HTMLResource.VehiclePremiumSection1);
string vp2 = BuildVPStr(LobjCurrentVehiclePremiumsList, HTMLResource.VehiclePremiumSection2);

Open in new window


you could use reflection to get all VehiclePremiumSection properties from HTMLResource and for each one, call the function and pass the value of the parameter:

foreach (PropertyInfo info in HTMLResource.GetType().GetProperties())
{
   if (info.CanRead && info.Name.Contains("VehiclePremiumSection"))
   {
      string vehiclePremiumSection = propertyInfo.GetValue(myObject, null).ToString();
//now call the function with this parameter
string result = BuildVPStr(LobjCurrentVehiclePremiumsList, vehiclePremiumSection);

   }
} 

Open in new window

0
 

Author Comment

by:RameshLathu
ID: 37824255
Thanks for quick reply. But, for all pror and current function call, I won't be having same line of code in the method. I have 16 html vehiclepremium string and I have 16 build str methods. But each method is replacing different strings. Please check below. Ofcourse, every method will be called, twice one for "Prior" and one for "Current". But 16 different methods will be there.

For eg, it will like below,

 private string BuildVP1Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
        {            
            int LiVehicleInfoResultID = 0;
            foreach (VehiclePremiums LobjVP in PobjVPList)
            {
                LiVehicleInfoResultID++;                
                string LstrVP = HTMLResource.VehiclePremiumSection1;
                //LstrVP = LstrVP.Replace("VP_VehicleInfoResultIDValue", LobjVP.VehicleInfoResultID.ToString());
                LstrVP = LstrVP.Replace("VP_VehicleInfoResultIDValue", LiVehicleInfoResultID.ToString());
                LstrVP = LstrVP.Replace("VP_PolicyInfoTypeValue", PstrPolicyInfoType);
                LstrVP = LstrVP.Replace("VP_VehicleSequenceNumberValue", LobjVP.VehicleSequenceNumber);
                LstrVP = LstrVP.Replace("VP_VehicleNumberValue", LobjVP.VehicleNumber.ToString());
                LstrVP = LstrVP.Replace("VP_VehicleClassValue", LobjVP.VehicleClass);
                LstrVP = LstrVP.Replace("VP_LiabilityPremiumValue", LobjVP.LiabilityPremium.ToString());
                LstrVP = LstrVP.Replace("VP_MedicalPaymentsPremiumValue", LobjVP.MedicalPaymentsPremium.ToString());
                LstrVP = LstrVP.Replace("VP_UMUIMPremiumValue", LobjVP.UMUIMPremium.ToString());
                LstrVP = LstrVP.Replace("VP_PIPPremiumValue", LobjVP.PIPPremium.ToString());
                LstrVP = LstrVP.Replace("VP_PIPHigherLimitsPremiumValue", LobjVP.PIPHigherLimitsPremium.ToString());

                PstrVP = PstrVP + LstrVP;          

            }

            return PstrVP;
        }

 private string BuildVP2Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
        {
            int LiVehicleInfoResultID = 0;
            foreach (VehiclePremiums LobjVP in PobjVPList)
            {
                LiVehicleInfoResultID++;
                string LstrVP = HTMLResource.VehiclePremiumSection2;
                LstrVP = LstrVP.Replace("VP_VehicleInfoResultIDValue", LiVehicleInfoResultID.ToString());
                LstrVP = LstrVP.Replace("VP_PolicyInfoTypeValue", PstrPolicyInfoType);
                LstrVP = LstrVP.Replace("VP_VehicleSequenceNumberValue", LobjVP.VehicleSequenceNumber);
                LstrVP = LstrVP.Replace("VP_VehicleNumberValue", LobjVP.VehicleNumber.ToString());

                LstrVP = LstrVP.Replace("VP_ComprehensivePremiumValue", LobjVP.ComprehensivePremium.ToString());
                LstrVP = LstrVP.Replace("VP_CollisionPremiumValue", LobjVP.CollisionPremium.ToString());
                LstrVP = LstrVP.Replace("VP_IncreasedTEPremiumValue", LobjVP.IncreasedTEPremium.ToString());
                LstrVP = LstrVP.Replace("VP_AudioVisualPremiumValue", LobjVP.AudioVisualPremium.ToString());
                LstrVP = LstrVP.Replace("VP_TowingPremiumValue", LobjVP.TowingPremium.ToString());
                LstrVP = LstrVP.Replace("VP_VehiclePremiumValue", LobjVP.VehiclePremium.ToString());

                PstrVP = PstrVP + LstrVP;
            }
            return PstrVP;
        }
0
 

Author Comment

by:RameshLathu
ID: 37824274
and thid Buildstr method will be as below,

  private string BuildVP3Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
        {
            int LiVehicleInfoResultID = 0;
            foreach (VehiclePremiums LobjVP in PobjVPList)
            {
                LiVehicleInfoResultID++;
                string LstrVP = HTMLResource.VehiclePremiumSection3;
                LstrVP = LstrVP.Replace("VP_VehicleInfoResultIDValue", LiVehicleInfoResultID.ToString());
                LstrVP = LstrVP.Replace("VP_PolicyInfoTypeValue", PstrPolicyInfoType);
                LstrVP = LstrVP.Replace("VP_VehicleSequenceNumberValue", LobjVP.VehicleSequenceNumber);
                LstrVP = LstrVP.Replace("VP_VehicleNumberValue", LobjVP.VehicleNumber.ToString());

                LstrVP = LstrVP.Replace("VP_VehicleRankValue", LobjVP.VehicleRank.ToString());
                LstrVP = LstrVP.Replace("VP_ClassicModelYearValue", LobjVP.ClassicModelYear.ToString());
                LstrVP = LstrVP.Replace("VP_AssignedDriverNumberValue", LobjVP.AssignedDriverNumber.ToString());
                LstrVP = LstrVP.Replace("VP_VehicleClassDescriptionValue", LobjVP.VehicleClassDescription);
                LstrVP = LstrVP.Replace("VP_AssignedDDDriverNumberValue", LobjVP.AssignedDDDriverNumber.ToString());

                PstrVP = PstrVP + LstrVP;
            }
            return PstrVP;
        }


and in the same, I will be having different set of code for each method.
0
 

Author Comment

by:RameshLathu
ID: 38031879
Thanks
0

Featured Post

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

718 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