Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to write a program in c# whose input will be a c# project and on executing it, it should detect and merge each partial class to single files and remove partial tag. In simple words i want to remove partial classes feature in my sources.
Posted

But why? Partial classes are convenient ways to organize code in large classes. I use them quite often. This project is so preposterous, that I can only assume this is some sort of homework assignment.

If you wrote the code you're trying to "optimize", you shouldn't have any problems merging your partial classes into single files. If you get into this project and have a specific problem, come back and ask that specific question.
 
Share this answer
 
v2
Comments
Mohsan Raza Ali 4-Jul-11 12:16pm    
Actually am using a third party c# code parser which does not supports partial classes.
Sergey Alexandrovich Kryukov 4-Jul-11 20:30pm    
Mohsan, are you sure you need it? Please see my answer, may be it will give you the alternative idea.

John gets my 5 for the answer.
--SA
Mohsan Raza Ali 5-Jul-11 1:37am    
Actually i started using System.CodeDom, and its helpfull.
That is not a simple job: to be sure you don't mess anything up, you will have to read and do at least a basic parse on the entire source file. You need to know how many classes it contains, and making sure that you know the fully qualified name of each: Namespace, basic class, classes within classes.

Why do that anyway? Partial classes are a very useful feature: they allow us to keep the files small, and to group logical parts of a class.
 
Share this answer
 
Comments
OriginalGriff 4-Jul-11 14:14pm    
Perhaps if you had googled in the first place, you could have saved yourself, me, and JSOP some time?
#realJSOP 4-Jul-11 17:12pm    
Stop being an ass. We're the only two people that even took the time to answer you, and we both gave you pretty much the same answer. If you're using a parser that doesn't support partial classes, what else doesn't it support, and why would you want to commit code to it?
Sergey Alexandrovich Kryukov 4-Jul-11 20:29pm    
I agree, my 5. Maybe fixing or dumping this idiotic C# parser is easier? :-)
Well, take a look at my solution (suggestion).
--SA

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