Link to home
Start Free TrialLog in
Avatar of RameshLathu
RameshLathuFlag for United States of America

asked on

C#

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..................
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RameshLathu

ASKER

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;
        }
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.
Thanks