I am developing software and I need to change the accessibility of a class swiftly. The main reason for this is that during the testing process, the class must be public to be seen from the test module, in the production, the class should be internal. Here is a sample:
public interface ILdapService : IDisposable
{
// It will be internal in production. (TODO)
// YAP1 It will be public in the test. ()
/// <summary>
///
/// </summary>
/// <param name="email">Ldap user name without domain name</param>
/// <param name="password">Ldap passsword.</param>
bool Verify(string email, string password);
}
I am handling the issue through the Visual Studio editor tags, however, it increases the time needed to build the software. I am using the preprocessor tags for conditional build and change can be done swiftly, but changing accessibility is a problem. How can I do this? Thanks in advance.
>Solution :
The main reason for this is that during the testing process, the class must be public to be seen from the test module, in the production, the class should be internal.
Sounds like what you really want is to make it internal, but use InternalsVisibleToAttribute to still have access to it from the test project.
Just apply [assembly:InternalsVisibleTo("YourTestProject")] in your production project and you should be fine. (In my experience this is the most common reason for using InternalsVisibleTo. There are plenty of people who say you shouldn’t test anything that isn’t actually public, but personally I find testing internal classes to be very pragmatic.)