Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (var item in projectToWrite)
            {
                // Create an output file



                StringBuilder builder = new StringBuilder();
                msbuildFile.WriteLine(GetMSBuildFileHeader());
                msbuildFile.WriteLine(GetMSBuildFileItem(item, compilerOutputPath));


               // Add the Details
                if (item.Type == ProjectTypes.CPP)
                {

                 //WriteBuildFileFooterCPP(msbuildFile);
                    WriteBuildFileFooterCPP(msbuildFile);

                }

                else if (item.Type == ProjectTypes.Cs)
                {

                    //builder.Append(ProjectTypes.Cs);
                    WriteBuildFileFooterCS(msbuildFile);
                }
                else if (item.Type == ProjectTypes.VB)
                {
                  //builder.Append(ProjectTypes.VB);
                    WriteBuildFileFooterVB(msbuildFile);
                }


                msbuildFile.WriteLine(GetMSBuildFileFooter());


            }

            msbuildFile.Flush();
            msbuildFile.Close();
        }
Posted
Comments
CPallini 18-Nov-11 4:22am    
What are the 'functions' you need to change? And what is the problem in returning a string?
BillWoodruff 18-Nov-11 7:07am    
Are you wanting to return on string for each iteration of the foreach loop: or are you wanting to return one string which contains all the strings produced by the iterations of the foreach loop ?

Replace the WriteLines with AppendLine instructions:
C#
StringBuilder builder = new StringBuilder();
foreach (var item in projectToWrite)
{
    // Create an output file
    builder.AppendLine(GetMSBuildFileHeader());
    builder.AppendLine(GetMSBuildFileItem(item, compilerOutputPath));
And so forth.
NOTE: I moved the string builder outside the loop, so it assembles data for all strings.

Then, at the end:
C#
return builder.ToString();
 
Share this answer
 
Comments
rajeevcapgeminiindia 18-Nov-11 4:32am    
Please clarify your question.
If you want to return all the appended(assembled) string at last then move StringBuilder class outside the loop.
If not then Clarify the qusetion.
If I'm reading this correctly then it seems to me that you just need to uncomment your string builder append lines and put this loop into a function that returns a string - your last line would then be

C#
return builder.ToString()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900