Solved

C#

Posted on 2012-04-09
5
229 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
  • 3
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now