{"id":308134,"date":"2020-08-07T09:00:34","date_gmt":"2020-08-07T09:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308134"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-08-07T09:00:34","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308134","title":{"rendered":"\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/513062\/\">\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u0438 \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u0431\u044b\u043b \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 C#. \u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0440\u0443\u0434\u0438\u0446\u0438\u044e \u0438 \u0437\u0430\u044f\u0432\u0438\u043b, \u0447\u0442\u043e \u0432\u043e\u0442 \u0432 Java \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0438 C#, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043b\u043e\u0436\u044c\u044e, \u0432\u0440\u0430\u043d\u044c\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u043e\u043a\u0430\u0446\u0438\u0435\u0439<\/b>                         <\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/uw\/qv\/hc\/uwqvhcmhh7vh8zhmbyclmloynxy.png\" alt=\"image\">  <\/div>\n<\/p><\/div>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0438\u043c\u0435\u043b\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0431\u044b\u043b \u043f\u0440\u0438\u043d\u044f\u0442.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/post\/513062\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/h-\/_i\/0j\/h-_i0j_k01euzuqqky3lccmxwhw.png\" alt=\"image\"><\/a><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u0435\u043c\u044b \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438. \u0422\u043e\u0447\u043d\u0435\u0435 \u0434\u0430\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0442\u0435\u043c\u0430 \u0434\u043b\u044f \u043b\u0435\u0433\u043a\u043e\u0433\u043e \u0441\u0432\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u0430 \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u043e\u0439. \u0418\u043b\u0438 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u0443\u044e\u0449\u0438\u043c.  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0438\u043f\u0435 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"cs\">public class A {     public A()     {         Console.WriteLine($&quot;Type '{nameof(A)}' .ctor called on object #{GetHashCode()}&quot;);     } }  public class B : A {     public B()     {         Console.WriteLine($&quot;Type '{nameof(B)}' .ctor called on object #{GetHashCode()}&quot;);     } }  public class C : B {     public C()     {         Console.WriteLine($&quot;Type '{nameof(C)}' .ctor called on object #{GetHashCode()}&quot;);     } } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<pre><code class=\"cs\">class Program {     static void Main()     {         new C();     } } <\/code><\/pre>\n<p>  \u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434:<\/p>\n<p>  <code>Type 'A' .ctor called on object #58225482<br \/>  Type 'B' .ctor called on object #58225482<br \/>  Type 'C' .ctor called on object #58225482<br \/>  <\/code>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u041f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430, \u043b\u0438\u0431\u043e \u043b\u044e\u0431\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u044f\u0432\u043d\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0415\u0441\u043b\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u0430\u043c \u0441\u0435\u0431\u044f:<\/p>\n<pre><code class=\"cs\">public A() : this() { } \/\/ CS0516  Constructor 'A.A()' cannot call itself <\/code><\/pre>\n<p>  \u0438 \u0442\u0430\u043a\u0438\u043c \u0444\u043e\u043a\u0443\u0441\u043e\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438:<\/p>\n<pre><code class=\"cs\">public A() : this(new object()) { } public A(object _) : this(0) { } public A(int _) : this() { } \/\/ CS0768  Constructor 'A.A(int)' cannot call itself through another constructor <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430<\/h4>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cs\">internal static class Extensions {     public static void Trace(this object obj) =&gt;         Console.WriteLine($&quot;Type '{obj.GetType().Name}' .ctor called on object #{obj.GetHashCode()}&quot;); } <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u043e \u0432\u0441\u0435\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445<\/p>\n<pre><code class=\"cs\">Console.WriteLine($&quot;Type '{nameof(...)}' .ctor called on object #{GetHashCode()}&quot;); <\/code><\/pre>\n<p>  \u043d\u0430<\/p>\n<pre><code class=\"cs\">this.Trace(); <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<p>  <code>Type 'C' .ctor called on object #58225482<br \/>  Type 'C' .ctor called on object #58225482<br \/>  Type 'C' .ctor called on object #58225482<br \/>  <\/code><br \/>  \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044c. \u041a\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u0438\u043f\u0430\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438? \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440. \u0410 \u0435\u0449\u0435 \u043e\u043d \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432. \u0418 \u0434\u043b\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u0436\u0435 \u043e\u043d. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0442\u0438\u043f\u043e\u0432, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0432 \u043c\u0435\u0442\u043e\u0434 <i><b>Trace<\/b><\/i> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">public static void Trace&lt;T&gt;(this T obj) =&gt;     Console.WriteLine($&quot;Type '{typeof(T).Name}' .ctor called on object #{obj.GetHashCode()}&quot;); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0443 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430<\/h4>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044f. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <i><b>Extensions<\/b><\/i> \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"cs\">public static Action GetBaseConstructor&lt;T&gt;(this T obj) =&gt;     () =&gt; typeof(T)           .BaseType           .GetConstructor(Type.EmptyTypes)           .Invoke(obj, Array.Empty&lt;object&gt;()); <\/code><\/pre>\n<p>  \u0412 \u0442\u0438\u043f\u044b <i><b>B<\/b><\/i> \u0438 <i><b>C<\/b><\/i> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e:<\/p>\n<pre><code class=\"cs\">private Action @base =&gt; this.GetBaseConstructor(); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435<\/h4>\n<p>  \u041c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 <i><b>B<\/b><\/i> \u0438 <i><b>C<\/b><\/i> \u043d\u0430:<\/p>\n<pre><code class=\"cs\">this.Trace(); @base(); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0432\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <code>Type 'A' .ctor called on object #58225482<br \/>  Type 'B' .ctor called on object #58225482<br \/>  Type 'A' .ctor called on object #58225482<br \/>  Type 'C' .ctor called on object #58225482<br \/>  Type 'A' .ctor called on object #58225482<br \/>  Type 'B' .ctor called on object #58225482<br \/>  Type 'A' .ctor called on object #58225482<br \/>  <\/code>  <\/p>\n<h4>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430<\/h4>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u0442\u0438\u043f\u0430 <i><b>A<\/b><\/i> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f:<\/p>\n<pre><code class=\"cs\">protected class CtorHelper {     private CtorHelper() { } } <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u0438\u043f\u0430 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430. \u0422\u0438\u043f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043e\u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0442\u0438\u043f\u0430 <i><b>A<\/b><\/i> \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u043e\u0442 \u043d\u0435\u0433\u043e. \u041f\u043e \u044d\u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0442\u0438\u043f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 <i><b>A<\/b><\/i> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u043c.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <i><b>A<\/b><\/i>, <i><b>B<\/b><\/i> \u0438 <i><b>C<\/b><\/i> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"cs\">protected A(CtorHelper _) { } protected B(CtorHelper _) { } protected C(CtorHelper _) { } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u0438\u043f\u043e\u0432 <i><b>B<\/b><\/i> \u0438 <i><b>C<\/b><\/i> \u043a\u043e \u0432\u0441\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432:<\/p>\n<pre><code class=\"cs\">: base(null) <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">internal static class Extensions {     public static Action GetBaseConstructor&lt;T&gt;(this T obj) =&gt;         () =&gt; typeof(T)         .BaseType         .GetConstructor(Type.EmptyTypes)         .Invoke(obj, Array.Empty&lt;object&gt;());      public static void Trace&lt;T&gt;(this T obj) =&gt;         Console.WriteLine($&quot;Type '{typeof(T).Name}' .ctor called on object #{obj.GetHashCode()}&quot;); }  public class A {     protected A(CtorHelper _) { }      public A()     {         this.Trace();     }      protected class CtorHelper     {         private CtorHelper() { }     } }  public class B : A {     private Action @base =&gt; this.GetBaseConstructor();      protected B(CtorHelper _) : base(null) { }      public B() : base(null)     {         this.Trace();         @base();     } }  public class C : B {     private Action @base =&gt; this.GetBaseConstructor();      protected C(CtorHelper _) : base(null) { }      public C() : base(null)     {         this.Trace();         @base();     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  \u0418 \u0432\u044b\u0432\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f:<\/p>\n<p>  <code>Type 'C' .ctor called on object #58225482<br \/>  Type 'B' .ctor called on object #58225482<br \/>  Type 'A' .ctor called on object #58225482<br \/>  <\/code>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u0430\u0447\u043e\u043a \u0434\u0443\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u043c\u0430\u043d\u0443\u043b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440<\/b>                         <\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/84\/ol\/b0\/84olb0cw_v49hlxbdcale1q8sdy.gif\" alt=\"image\">  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h4>\u041e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430<\/h4>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 <i><b>Extensions<\/b><\/i> \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"cs\">public static void TraceSurrogate&lt;T&gt;(this T obj) =&gt;     Console.WriteLine($&quot;Type '{typeof(T).Name}' surrogate .ctor called on object #{obj.GetHashCode()}&quot;); <\/code><\/pre>\n<p>  \u0438 \u0432\u044b\u0437\u0432\u0430\u0432 \u0435\u0433\u043e \u0432\u043e \u0432\u0441\u0435\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 <i><b>CtorHelper<\/b><\/i>, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u044b\u0432\u043e\u0434:<\/p>\n<p>  <code>Type 'A' surrogate .ctor called on object #58225482<br \/>  Type 'B' surrogate .ctor called on object #58225482<br \/>  Type 'C' .ctor called on object #58225482<br \/>  Type 'A' surrogate .ctor called on object #58225482<br \/>  Type 'B' .ctor called on object #58225482<br \/>  Type 'A' .ctor called on object #58225482<br \/>  <\/code><br \/>  \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0431\u0430\u0437\u043e\u0432\u044b\u0439\/\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0439, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f. \u041d\u043e \u0432\u0441\u0435 \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432, \u043d\u0435\u0441\u0443\u0449\u0438\u0445 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443, \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u044b \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432.<\/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=\"https:\/\/habr.com\/ru\/post\/513062\/\"> https:\/\/habr.com\/ru\/post\/513062\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/513062\/\">\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u0438 \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u0431\u044b\u043b \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 C#. \u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0440\u0443\u0434\u0438\u0446\u0438\u044e \u0438 \u0437\u0430\u044f\u0432\u0438\u043b, \u0447\u0442\u043e \u0432\u043e\u0442 \u0432 Java \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0438 C#, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043b\u043e\u0436\u044c\u044e, \u0432\u0440\u0430\u043d\u044c\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u043e\u043a\u0430\u0446\u0438\u0435\u0439<\/b>                         <\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/uw\/qv\/hc\/uwqvhcmhh7vh8zhmbyclmloynxy.png\" alt=\"image\">  <\/div>\n<\/p><\/div>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0438\u043c\u0435\u043b\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0431\u044b\u043b \u043f\u0440\u0438\u043d\u044f\u0442.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/post\/513062\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/h-\/_i\/0j\/h-_i0j_k01euzuqqky3lccmxwhw.png\" alt=\"image\"><\/a>  <\/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-308134","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308134","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=308134"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308134\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}