Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working in a solution in Visual Studio (C#) that has a lot of code that shouldn't be changed. That is, only a small portion of the code files should be altered.

What would be the best way to show this to other programmers? I'm thinking that the ideal solution would be to be able to "highlight" the hands-off code using a gray color, but I don't think that's possible. Perhaps the best way is to use regions?

In case this question was a bit unclear: Let's say a code file has ten variables declared and thirteen methods. I don't want the other programmers to make changes to seven of the variables and to nine of the methods. How do I signal this in an easy and clear way?

In addition, some files and even two of the three projects in the solution should stay intact. Is there a way to show this (or perhaps to lock them)?

Thanks for any suggestions!

Petter

What I have tried:

I have tried to search for a good way of doing this, but don't really know what to look for. It's hard to search for this, as "code" and "highlight" gives me the wrong results.
Posted
Updated 18-Jun-16 18:21pm
Comments
ZurdoDev 14-Jun-16 7:45am    
I am not familiar with any method to do this other than regions. However, most importantly is to use some source control. There may be a 3rd party product that allows security at the line level but you'd have to search google.
May be some Visual Studio Plugin.
petter2012 14-Jun-16 8:54am    
Okey, thank you. It would be handy though! It could be used not only for hindering changes but also for pointing to relevant code.

Big picture: what you are talking about is usually resolved (by a programming team) by using version control software.

Consider putting the parts of the code you do not wish modified in separate assemblies. Define Classes in these assemblies that expose some members via 'Public or 'Protected access modifiers. Possibly make these classes "singletons" (?).

Of course you can use "partial classes" to split up the code; it's also possible to go into the file system, select the .cs file containing the partial Class and make it read-only. Note: I have not tried this.
 
Share this answer
 
Comments
petter2012 20-Jun-16 9:54am    
Thanks Bill!

That was actually several good suggestions. For this particular project I'll stick to a partial class, as that makes getting to XAML stuff mush easier. (In this case tht framweork is written by another person so digging into that would mean some work for me.)

Still, I think it would be nice to have coloring/highlighing available in VS. I wonder why this has never been implemented.

Thanks again,

Petter
I'm satisfied with the solutions above (trying to close the question).
 
Share this answer
 
Comments
petter2012 18-Jun-16 4:02am    
Hi again,

To anyone looking for an answer to this question: I suddenly remembered that partial classes are great for this. I'm now using a partial class as a "wrapper" or an interface between the normal code-behind code and the more elaborate classes. This means that another coder can't (easily) accidentally trash the "wrapping" code.

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