RameshLathu
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(LobjCurrentVeh iclePremiu msList, LstrCurrentVP1, "Current");
LstrPriorVP1 = BuildVP1Str(LobjPriorVehic lePremiums List, LstrPriorVP1, "Prior");
PstrVP1 = LstrCurrentVP1 + LstrPriorVP1;
LstrCurrentVP2 = BuildVP2Str(LobjCurrentVeh iclePremiu msList, LstrCurrentVP2, "Current");
LstrPriorVP2 = BuildVP2Str(LobjPriorVehic lePremiums List, 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.VehiclePremiu mSection1;
LstrVP = LstrVP.Replace("VP_PolicyI nfoTypeVal ue", PstrPolicyInfoType);
LstrVP = LstrVP.Replace("VP_Liabili tyPremiumV alue", LobjVP.LiabilityPremium.To String());
.....
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}
private string BuildVP2Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
{
foreach (VehiclePremiums LobjVP in PobjVPList)
{
string LstrVP = HTMLResource.VehiclePremiu mSection2;
LstrVP = LstrVP.Replace("VP_PolicyI nfoTypeVal ue", PstrPolicyInfoType);
LstrVP = LstrVP.Replace("VP_Compreh ensivePrem iumValue", LobjVP.ComprehensivePremiu m.ToString ());
...........
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}
Please help..................
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(LobjCurrentVeh
LstrPriorVP1 = BuildVP1Str(LobjPriorVehic
PstrVP1 = LstrCurrentVP1 + LstrPriorVP1;
LstrCurrentVP2 = BuildVP2Str(LobjCurrentVeh
LstrPriorVP2 = BuildVP2Str(LobjPriorVehic
PstrVP2 = LstrCurrentVP2 + LstrPriorVP2;
private string BuildVP1Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
{
int LiVehicleInfoResultID = 0;
foreach (VehiclePremiums LobjVP in PobjVPList)
{
string LstrVP = HTMLResource.VehiclePremiu
LstrVP = LstrVP.Replace("VP_PolicyI
LstrVP = LstrVP.Replace("VP_Liabili
.....
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}
private string BuildVP2Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
{
foreach (VehiclePremiums LobjVP in PobjVPList)
{
string LstrVP = HTMLResource.VehiclePremiu
LstrVP = LstrVP.Replace("VP_PolicyI
LstrVP = LstrVP.Replace("VP_Compreh
...........
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}
Please help..................
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.VehiclePremiu mSection3;
LstrVP = LstrVP.Replace("VP_Vehicle InfoResult IDValue", LiVehicleInfoResultID.ToSt ring());
LstrVP = LstrVP.Replace("VP_PolicyI nfoTypeVal ue", PstrPolicyInfoType);
LstrVP = LstrVP.Replace("VP_Vehicle SequenceNu mberValue" , LobjVP.VehicleSequenceNumb er);
LstrVP = LstrVP.Replace("VP_Vehicle NumberValu e", LobjVP.VehicleNumber.ToStr ing());
LstrVP = LstrVP.Replace("VP_Vehicle RankValue" , LobjVP.VehicleRank.ToStrin g());
LstrVP = LstrVP.Replace("VP_Classic ModelYearV alue", LobjVP.ClassicModelYear.To String());
LstrVP = LstrVP.Replace("VP_Assigne dDriverNum berValue", LobjVP.AssignedDriverNumbe r.ToString ());
LstrVP = LstrVP.Replace("VP_Vehicle ClassDescr iptionValu e", LobjVP.VehicleClassDescrip tion);
LstrVP = LstrVP.Replace("VP_Assigne dDDDriverN umberValue ", LobjVP.AssignedDDDriverNum ber.ToStri ng());
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}
and in the same, I will be having different set of code for each method.
private string BuildVP3Str(ArrayList PobjVPList, string PstrVP, string PstrPolicyInfoType)
{
int LiVehicleInfoResultID = 0;
foreach (VehiclePremiums LobjVP in PobjVPList)
{
LiVehicleInfoResultID++;
string LstrVP = HTMLResource.VehiclePremiu
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_PolicyI
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Classic
LstrVP = LstrVP.Replace("VP_Assigne
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Assigne
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}
and in the same, I will be having different set of code for each method.
ASKER
Thanks
ASKER
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.VehiclePremiu
//LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_PolicyI
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Liabili
LstrVP = LstrVP.Replace("VP_Medical
LstrVP = LstrVP.Replace("VP_UMUIMPr
LstrVP = LstrVP.Replace("VP_PIPPrem
LstrVP = LstrVP.Replace("VP_PIPHigh
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.VehiclePremiu
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_PolicyI
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Vehicle
LstrVP = LstrVP.Replace("VP_Compreh
LstrVP = LstrVP.Replace("VP_Collisi
LstrVP = LstrVP.Replace("VP_Increas
LstrVP = LstrVP.Replace("VP_AudioVi
LstrVP = LstrVP.Replace("VP_TowingP
LstrVP = LstrVP.Replace("VP_Vehicle
PstrVP = PstrVP + LstrVP;
}
return PstrVP;
}