Possible duplicate:Why the XML-Serializable class needs a parameterless constructor
Does anyone know if it is possible to prevent a public constructor from being called outside the assembly range?
What I'm doing is a class library that has classes that are serializable by XML. These classes do not make sense if they are designed without setting various properties, so I want to prevent this condition.
I am wondering if there is a way to stop someone from calling my public constructor and keeping it there only for serialization?
, , .
public foo() { this.bar = -1; } public foo(int bar) { this.bar = bar; }
/ , Factory, .
, , , , , getInstance , getInstance. getInstance, , .
, , :
if (Assembly.GetCallingAssembly().GetName().Name == "Forbidden.Assembly") { throw new Exception(...); }
Source: https://habr.com/ru/post/1712665/More articles:Creating thumbnails from swf file in php? - phpHow to check if a private method has been called with the expected argument in unit test? - c #Portable way to determine total disk size in Java (pre java 6) - javaDoes BitArray list a lot of boxing / unboxing? - performance"order by" taking too long in mysql - mysqllibrary for sending trackbacks / pingbacks in php - trackbackΠΡΠΎΠ±Π»Π΅ΠΌΠ° Ρ Javascript - javascriptWPF / C #: disable drag and drop for text fields? - c #exchange attributes openid - attributesWhy is my task not working on CruiseControl (cannot find nunit)? - nunitAll Articles