Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Restrict class from instantiation and encapsulate it in property in another class

$
0
0

Im writing a .net Standard class library and I want to publish it as an internal package,so i have two classes in same project let say as below :

 public class classOne{     public void SomeMethod()        {        }} public class classTwo{     private ClassOne _classOne;     public classOne clsOne        {            get            {                lock (padlock)                {                    if (_classOne== null)                        _classOne= new ClassOne ();                    return _classOne;                }            }        }}

As you seen above I want the developers to use class one as a property inside classTwo Also I want to prevent the instantiation of classOne. just the only way to call classOne methods is through classTwo "clsOne" property.

    //I want this codeclassTwo clsTwo = new classTwo();clsTwo.clsOne.someMethod();//And Prevent to do this codeclassOne clsOnew= new classOne();clsOne.someMethod();

how do i implement that ?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>