stylojack_10 stylojack_10 - 2 months ago 14
C# Question

How to define a method only for one client and restrict access to other clients?

I was asked this in an interview. Say I have a dll (or a class) with multiple methods that is used by 10 clients. Now one of the clients needs to change a method and add a new method to the class. How can this be achieved without the other clients accessing the new method?

Answer

It seems that you shoud create a new class which is derived from the original class and has an additional fuctionality. For example:

public class OriginalClass 
{
    public int SomeOriginalMethod() { }
}

public class YourNewClass : OriginalClass
{
    public int SomeNewMethod() { }
}

There are two benifits there. Your client will obtain new functionality and other clients will still use your original class. If you would like to limit access to new functioanlity you can add new methods asinternal in your original class and use InternalsVisibleTo attribute to provide an access only for clients you want