I’m writing a library that has a bunch of classes in it which are intended to be used by multiple frontends (some frontends share the same classes). For each frontend, I am keeping a hand edited list of which classes (of a particular namespace) it uses. If the frontend tries to use a class that is not in this list, there will be runtime errors. My goal is to move these errors to compile time.
If any of you are curious, these are ‘mapped’ nhibernate classes. I’m trying to restrict which frontend can use what so that there is less spin up time, and just for my own sanity. There’s going to be hundreds of these things eventually, and it will be really nice if there’s a list somewhere that tells me which frontends use what that I’m forced to maintain. I can’t seem to get away with making subclasses to be used by each frontend and I can’t use any wrapper classes… just take that as a given please!
Ideally, I want visual studio to underline red the offending classes if someone dares to try and use them, with a nice custom error in the errors window. I also want them GONE from the intellisense windows. Is it possible to customize a project to do these things?
I’m also open to using a pre-build program to analyze the code for these sorts of things, although this would not be as nice. Does anyone know of tools that do this?
Thanks
Isaac
Let’s say that you have a set of classes
F. You want these classes to be visible only to a certain assemblyA. Then you segregate these classes inFinto a separate assembly and mark them asinternaland set theInternalsVisibleToon that assembly to true for this certain assemblyA.If you try to use these classes from any assembly
A'that is not marked asInternalsVisibleTofrom the assembly containingF, then you will get a compile-time error if you try to use any class fromFinA'.That happens with the solution I presented above as well. They are internal to the assembly containing
Fand not visible from any assemblyA'not marked asInternalsVisibleToin the assembly containingF.However, I generally find that
InternalsVisibleTois a code smell (not always, just often).