Search code examples
asp.net.netclassrestriction

How to restrict class usage


Is there a way to enforce a class only to be used in ASP.NET ? So that it can't be referenced in a WinForm app or throw exception when instantiated. Is there some kind of .NET class attribute for this purpose?


Solution

  • Don't!!!

    public class WebOnly
    {
        public WebOnly()
        {
            if (HttpContext.Current == null)
                throw new Exception("me needs web");
        }
    }