{"id":190380,"date":"2013-08-17T01:46:03","date_gmt":"2013-08-16T21:46:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=190380"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=190380","title":{"rendered":"<span class=\"post_title\">Singleton serialization \u0438\u043b\u0438 \u0441\u0430\u0434 \u043a\u0430\u043c\u043d\u0435\u0439<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/989\/646\/257\/98964625779826612d8d33af89fe1d70.png\" alt=\"image\"\/><\/p>\n<p>  \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d, \u043d\u043e \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0439. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0435\u0442\u0440\u0443\u0434\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435\u043c \u0432 \u0441\u0430\u0434 \u043a\u0430\u043c\u043d\u0435\u0439 \u0438 \u0431\u0443\u043b\u044b\u0436\u043d\u0438\u043a\u043e\u0432: \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u043e\u0432 \u0434\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0439. <br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h5>\u041d\u043e \u0437\u0430\u0447\u0435\u043c \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c <s>\u043e\u0433\u043e\u0440\u043e\u0434<\/s> \u0441\u0430\u0434?<\/h5>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u0435\u0441\u043b\u0438 \u0442\u0430\u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0442\u043e \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0443\u0436\u043d\u043e? \u0422\u0430\u043a\u0430\u044f \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044c, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435 \u0447\u0430\u0441\u0442\u043e. \u0425\u043e\u0442\u044f \u043c\u043d\u043e\u0433\u0438\u0435 \u043b\u044e\u0434\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 WPF \u0438\u043b\u0438 WinForms, \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043d\u0435 \u0442\u0440\u0430\u0442\u044c\u0442\u0435 \u0441\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0439\u0442\u0435 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434: \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c Application \u0438 User Settings (\u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/k4s6c3a0.aspx\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"http:\/\/www.codeproject.com\/Articles\/25829\/User-Settings-Applied\">\u0437\u0434\u0435\u0441\u044c<\/a>). \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<br \/>  \u0425\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u043f\u043e \u0441\u0435\u0442\u0438 \u0438\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 AppDomain. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 ftp \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044e\u0442 \u0441\u0432\u043e\u0438 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u043d\u0435\u043c. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 ftp \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0435 (\u0438 \u0442\u0430\u043c \u0436\u0435 \u043f\u0440\u0438\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c).<br \/>  \u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c, \u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0445. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.dbnull.aspx\">DBNull<\/a>.  <\/p>\n<h5>\u0421\u0438\u043d\u0433\u043b\u0442\u043e\u043d<\/h5>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d:   <\/p>\n<pre><code class=\"cs\">public sealed class Settings : ISerializable {     private static readonly Settings Inst = new Settings();     private Settings()     {     }      public static Settings Instance     {         get { return Inst; }     }       public String ServerAddress     {         get { return _servAddr; }         set { _servAddr = value; }     }      public String Port     {         get { return _port; }         set { _port = value; }     }     private String _port = &quot;&quot;; } <\/code><\/pre>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043f\u043e \u043a\u043e\u0434\u0443:  <\/p>\n<ul>\n<li>\u041d\u0430\u043c\u0435\u0440\u0435\u043d\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043a\u043e\u0434.<\/li>\n<li>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438, \u0442.\u043a. \u0438\u043c\u0435\u043d\u0430 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u043a\u043b\u0430\u0441\u0441\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0438 \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0447\u0435\u0441\u0442\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0443\u0436\u0435 \u043d\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u044d\u0442\u0438\u0445 \u0438\u043c\u0435\u043d.<\/li>\n<\/ul>\n<p>  <\/p>\n<h5>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434<\/h5>\n<p>  \u0412 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 C# \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.serializableattribute.aspx\">Serializable<\/a>. \u0427\u0442\u043e \u0436, \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u043b\u043e\u0436\u0435\u043d \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u0432 \u0442\u0440\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.serialization.formatters.soap.soapformatter.aspx\">SOAP<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.serialization.formatters.binary.binaryformatter.aspx\">Binary<\/a> \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.xml.serialization.xmlserializer.aspx\"> XML<\/a>.<br \/>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u043e (\u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b):  <\/p>\n<pre><code class=\"cs\">using (var mem = new MemoryStream()) {     var serializer = new BinaryFormatter();     serializer.Serialize(mem, Settings.Instance);     mem.Seek(0, SeekOrigin.Begin);     object o = serializer.Deserialize(mem);     Console.WriteLine((Settings)o == Settings.Instance); } <\/code><\/pre>\n<p>  (\u041d\u0435)\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e false, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430. \u0422\u0430\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438 \u0432\u0441\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u043e\u0432\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430 \u043a\u043b\u0430\u0434\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c \u0432 \u043d\u0430\u0448 \u0441\u0430\u0434: \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u043e\u043c.<\/p>\n<h5>\u0423\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u043c \u0438\u2026 \u043a\u043b\u0430\u0434\u0435\u043c \u0435\u0449\u0435 \u043a\u0430\u043c\u0435\u043d\u0435\u0439.<\/h5>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u0431\u043e\u043b\u0435\u0435 \u201c\u0440\u0443\u0447\u043d\u043e\u043c\u0443\u201d \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.serialization.iserializable.aspx\">ISerializable<\/a>, \u0442\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0432\u044b\u0433\u043e\u0434\u044b \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0438\u043a\u0430\u043a\u043e\u0439: \u043f\u0440\u043e\u0448\u043b\u0430\u044f \u0431\u0435\u0434\u0430 \u043d\u0435 \u0438\u0441\u0447\u0435\u0437\u043b\u0430, \u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0437\u0440\u043e\u0441\u043b\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0430\u043c \u0435\u0449\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0435\u0434\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.serialization.iobjectreference.aspx\">IObjectReference<\/a>. \u0412\u0441\u0435 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442: \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438? \u041d\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c: \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e, \u0430 \u043d\u0430 \u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d. \u041a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">[Serializable] internal sealed class SettingsSerializationHelper : IObjectReference  {     public Object GetRealObject(StreamingContext context)      {         return Settings.Instance;     } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <i>SettingsSerializationHelper<\/i>, \u0430 \u043f\u0440\u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c <i>Settings.Instance<\/i>. \u041f\u0440\u0430\u0432\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0435\u0449\u0435 \u0434\u0432\u0430 \u043a\u0430\u043c\u043d\u044f:  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/li>\n<li>\u041f\u043e\u043b\u044f \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f.<\/li>\n<\/ul>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u043d, \u043d\u043e \u044f\u0432\u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u044f\u0442\u0435\u043d. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u0432 \u043f\u043e\u0434\u043c\u0435\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 <i>GetObjectData<\/i>. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a (\u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430):  <\/p>\n<pre><code class=\"cs\">public void GetObjectData(SerializationInfo info, StreamingContext context) {     info.SetType(typeof(SettingsSerializationHelper)); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u043e\u0431\u044a\u0435\u043a\u0442 <i>SettingsSerializationHelper<\/i>, \u0430 \u043f\u0440\u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430\u0448 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0432 \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438\u0437 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Binary \u0438 SOAP \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c true, \u043d\u043e \u0434\u043b\u044f XML \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 false. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, <i>XMLSerializer<\/i> \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <i>GetObjectData<\/i> \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 public \u043f\u043e\u043b\u044f\/\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<h5>\u0413\u0440\u044f\u0437\u043d\u044b\u0435 \u0445\u0430\u043a\u0438<\/h5>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u0435\u0439 \u2014 \u0441\u0430\u043c\u044b\u0439 \u043a\u0440\u0443\u043f\u043d\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u0430\u0434\u0443. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043c\u043d\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0435 \u0438 \u0447\u0435\u0441\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u043e\u043e\u0440\u0443\u0434\u0438\u0442\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0447\u0435\u0441\u0442\u043d\u044b\u0439, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0439 \u201c\u0445\u0430\u043a\u201d. <br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <i>GetObjectData <\/i> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">public void GetObjectData(SerializationInfo info, StreamingContext context) {     info.SetType(typeof(SettignsSerializeHelper));     info.AddValue(&quot;_servAddr&quot;, ServerAddressr);     info.AddValue(&quot;_port&quot;, Port); } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c SOAP \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043c\u044b \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b\u0438 <i>SettignsSerializationHelper<\/i>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u0442\u0438 \u043f\u043e\u043b\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u0440\u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:   <\/p>\n<ul>\n<li>\u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430 \u0432 <i>SettignsSerializationHelper<\/i>. \u0422\u0430\u043a\u0443\u044e \u043f\u043e\u0434\u043c\u0435\u043d\u0443 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u043a\u0443\u0448\u0430\u0435\u0442, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <i>GetRealObject<\/i> \u0438\u0445 \u043d\u0430\u0434\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0443. \u0423 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a: \u0440\u0443\u0447\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439, \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u044f\u0432\u043d\u043e \u043d\u0435 \u043d\u0430\u0448 <s>\u0431\u0440\u043e<\/s> \u0432\u044b\u0431\u043e\u0440.<\/li>\n<li>\u041f\u0440\u0438\u0437\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e, \u0441\u0443\u0440\u0440\u043e\u0433\u0430\u0442\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0438 \u0447\u0443\u0442\u043e\u0447\u043a\u0443 linq, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0437\u0430 \u043d\u0430\u0441. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435.<\/li>\n<\/ul>\n<p>  \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <i>GetObjectData<\/i>:  <\/p>\n<pre><code class=\"cs\">public void GetObjectData(SerializationInfo info, StreamingContext context) {     info.SetType(typeof (SettignsSerializeHelper));     var fields = from field in typeof (Settings).GetFields(BindingFlags.Instance |                     BindingFlags.NonPublic | BindingFlags.Public)                     where field.GetCustomAttribute(typeof (NonSerializedAttribute)) == null                     select field;     foreach (var field in fields)     {         info.AddValue(field.Name, field.GetValue(Settings.Instance));     } } <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u0432 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0436\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0437\u043e\u0432\u0430\u043d\u043d\u043e \u0431\u0435\u0437 \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0443\u043a\u0430\u043c\u0438. \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<br \/>  \u0412\u0441\u0435 \u043f\u043e\u043b\u044f \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u044b \u0432 <i>SettignsSerializationHelper<\/i>, \u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0438\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.serialization.iserializationsurrogate.aspx\">\u0441\u0443\u0440\u0440\u043e\u0433\u0430\u0442\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440<\/a> \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043c <i>SettignsSerializationHelper<\/i>. <br \/>  \u041d\u043e\u0432\u044b\u0439 <i>SettignsSerializationHelper<\/i>:  <\/p>\n<pre><code class=\"cs\">[Serializable] internal sealed class SettignsSerializeHelper : IObjectReference {     public readonly Dictionary&lt;String, object&gt; infos =              (from field in typeof (Settings).GetFields(BindingFlags.Instance               | BindingFlags.NonPublic | BindingFlags.Public)               where field.GetCustomAttribute(typeof (NonSerializedAttribute)) == null              select field).ToDictionary(x =&gt; x.Name, x =&gt; new object());      public object GetRealObject(StreamingContext context)     {         foreach (var info in infos)         {             typeof (Settings).GetField(info.Key, BindingFlags.Instance |  BindingFlags.NonPublic                                             | BindingFlags.Public).SetValue(Settings.Instance, info.Value);         }         return Settings.Instance;     } } <\/code><\/pre>\n<p>  \u0418 \u0442\u0430\u043a, \u0432\u043d\u0443\u0442\u0440\u0438 <i>SettignsSerializationHelper<\/i> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0445\u044d\u0448-\u043c\u0430\u043f, \u0433\u0434\u0435 key \u2014 \u0438\u043c\u0435\u043d\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439, \u0430 value \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0441\u0442\u0430\u043d\u0443\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u044d\u0442\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0437\u0430\u0446\u0438\u0438. \u0417\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c infos \u043a\u0430\u043a private \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043a\u0430 \u043a \u0435\u0433\u043e key-value \u043f\u0430\u0440\u0430\u043c, \u043d\u043e \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440. \u0412\u043d\u0443\u0442\u0440\u0438 <i>GetRealObject<\/i> \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0443 \u0435\u0433\u043e \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e. <br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c infos \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u043e\u043b\u0435\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440.   <\/p>\n<pre><code class=\"cs\">internal sealed class SettingsSurrogate : ISerializationSurrogate {     public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)     {         throw new NotImplementedException();     }     public object SetObjectData(object obj, SerializationInfo info, StreamingContext context,                                 ISurrogateSelector selector)     {         var ssh = new SettignsSerializeHelper();         foreach (var val in info)         {             ssh.infos[val.Name] = val.Value;         }         return ssh;     } } <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u043e \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e <i>SetObjectData<\/i>. \u041a\u043e\u0433\u0434\u0430 obj (\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442) \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u044c \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430, \u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b 0 \u0438 null \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u043e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432 (obj \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <i>GetUninitializedObject<\/i> \u0438\u0437 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.serialization.formatterservices.aspx\">FormatterServices<\/a>). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0449\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 <i>SettignsSerializationHelper<\/i> \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0433\u043e (\u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c). \u0414\u0430\u043b\u0435\u0435, \u0432\u043d\u0443\u0442\u0440\u0438 foreach \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c infos \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u044b \u043f\u043e\u043b\u044f\u043c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430. <br \/>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\/\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"cs\">\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\/\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438: using (var mem = new MemoryStream()) {     var soapSer = new SoapFormatter();     soapSer.Serialize(mem, Settings.Instance);     var ss = new SurrogateSelector();     ss.AddSurrogate(typeof(SettignsSerializeHelper),     soapSer.Context, new SettingsSurrogate());     soapSer.SurrogateSelector = ss;     mem.Seek(0, SeekOrigin.Begin);     var o = soapSer.Deserialize(mem);     Console.WriteLine((Settings)o == Settings.Instance); } <\/code><\/pre>\n<p>  \u041d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e true \u0438 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u043d\u0430\u0448 \u0441\u0430\u0434 \u043a\u0430\u043c\u043d\u0435\u0439 \u0432 \u0434\u043e\u043b\u0436\u043d\u044b\u0439 \u0432\u0438\u0434. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/190380\/\"> http:\/\/habrahabr.ru\/post\/190380\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/989\/646\/257\/98964625779826612d8d33af89fe1d70.png\" alt=\"image\"\/><\/p>\n<p>  \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d, \u043d\u043e \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0439. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0435\u0442\u0440\u0443\u0434\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435\u043c \u0432 \u0441\u0430\u0434 \u043a\u0430\u043c\u043d\u0435\u0439 \u0438 \u0431\u0443\u043b\u044b\u0436\u043d\u0438\u043a\u043e\u0432: \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u043e\u0432 \u0434\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0439.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-190380","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/190380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=190380"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/190380\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=190380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=190380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=190380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}