{"id":292002,"date":"2019-07-12T15:00:57","date_gmt":"2019-07-12T15:00:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=292002"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=292002","title":{"rendered":"\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c AutoMapper \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Roslyn \u0438 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/455952\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Roslyn. \u0422\u043e\u0433\u0434\u0430\u0448\u043d\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u0445\u043e\u0447\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435. <\/p>\n<p>  <\/p>\n<p>\u0418 \u0442\u0430\u043a, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 <a href=\"https:\/\/github.com\/AutoMapper\/AutoMapper\">AutoMapper<\/a> \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u0434\u0443\u043c\u0430\u044e \u0441\u0442\u043e\u0438\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043c\u043e\u0439 Ahead of Time Mapper(AOTMapper). \u0422\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043f\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435(generic extention method) <code>MapTo&lt;&gt;<\/code>. \u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>MapToUser<\/code>, \u0433\u0434\u0435 <code>User<\/code> \u044d\u0442\u043e \u0442\u0438\u043f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0432 <code>MapTo&lt;&gt;<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043a\u043b\u0430\u0441\u0441\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">namespace AOTMapper.Benchmark.Data {     public class UserEntity     {         public UserEntity()         {          }          public UserEntity(Guid id, string firstName, string lastName)         {             this.Id = id;             this.FirstName = firstName;             this.LastName = lastName;         }          public Guid Id { get; set; }         public string FirstName { get; set; }         public string LastName { get; set; }      }      public class User     {         public string FirstName { get; set; }         public string LastName { get; set; }          public string Name { get; set; }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0451\u043d\u043d\u044b\u0439 <code>MapToUser<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public static AOTMapper.Benchmark.Data.User MapToUser(this AOTMapper.Benchmark.Data.UserEntity input) {     var output = new AOTMapper.Benchmark.Data.User();     output.FirstName = input.FirstName;     output.LastName = input.LastName;     output.Name = ; \/\/ missing property      return output; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0442\u0435 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 &#171;\u0432\u0438\u0441\u0435\u0442\u044c&#187; \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u0430\u043a-\u0442\u043e \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public static AOTMapper.Benchmark.Data.User MapToUser(this AOTMapper.Benchmark.Data.UserEntity input) {     var output = new AOTMapper.Benchmark.Data.User();     output.FirstName = input.FirstName;     output.LastName = input.LastName;     output.Name = $\"{input.FirstName} {input.LastName}\";      return output; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <code>MapToUser<\/code> \u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>MapTo&lt;User&gt;<\/code> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0435\u043d\u043e \u043d\u0430 <code>MapToUser<\/code>. <\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442:<\/p>\n<p>  <\/p>\n<div class=\"oembed\">\n<div>\n<div style=\"left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.2493%;\"><iframe src=\"https:\/\/www.youtube.com\/embed\/BCznYk2n3II?rel=0&amp;showinfo=1&amp;hl=en-US\" style=\"border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;\" allowfullscreen scrolling=\"no\"><\/iframe><\/div>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 AOTMapper \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 nuget:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Install-Package AOTMapper<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/byme8\/AOTMapper\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  <\/p>\n<h1 id=\"realizaciya\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h1>\n<p>  <\/p>\n<p>\u042f \u0434\u043e\u043b\u0433\u043e \u0434\u0443\u043c\u0430\u043b \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435-\u043a\u043e\u043d\u0446\u043e\u0432 \u0441\u043e\u0448\u0435\u043b\u0441\u044f \u043d\u0430 \u043c\u044b\u0441\u043b\u0438, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043f\u043b\u043e\u0445\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0443\u0447\u0438\u043b\u0438 \u043c\u0435\u043d\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>AutoMapper<\/code>. <\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0432 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0447\u0435\u0433\u043e, \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0433\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>User<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 IntelliSense-\u0430 \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u043c\u0430\u043f\u0438\u043d\u0433\u0438 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u0444\u0430\u0439\u043b, \u0433\u0434\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0430\u0448\u0438 \u043c\u0430\u043f\u0438\u043d\u0433\u0438. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0443\u0436\u0435 \u0435\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u044b\u0445, \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u043b\u044e\u0431\u044b\u0445 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043f\u0435\u0440\u0430. \u042f \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 <code>AutoMapper<\/code> \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u0443\u0441\u0438\u043b\u0438\u0439 \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b\u0437\u043e\u0432\u0430, \u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0432\u0441\u0435\u0440\u0430\u0432\u043d\u043e \u0435\u0441\u0442\u044c. \u041c\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0447\u0442\u043e \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u044d\u0442\u043e 140-150ns \u043d\u0430 \u0432\u044b\u0437\u043e\u0432, \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0421\u0430\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043c\u0435\u0440\u043e\u0432 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Mean<\/th>\n<th>Error<\/th>\n<th>StdDev<\/th>\n<th>Gen 0<\/th>\n<th>Gen 1<\/th>\n<th>Gen 2<\/th>\n<th>Allocated<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>AutoMapperToUserEntity<\/td>\n<td>151.84 ns<\/td>\n<td>1.9952 ns<\/td>\n<td>1.8663 ns<\/td>\n<td>0.0253<\/td>\n<td>&#8212;<\/td>\n<td>&#8212;<\/td>\n<td>80 B<\/td>\n<\/tr>\n<tr>\n<td>AOTMapperToUserEntity<\/td>\n<td>10.41 ns<\/td>\n<td>0.2009 ns<\/td>\n<td>0.1879 ns<\/td>\n<td>0.0152<\/td>\n<td>&#8212;<\/td>\n<td>&#8212;<\/td>\n<td>48 B<\/td>\n<\/tr>\n<tr>\n<td>AutoMapperToUser<\/td>\n<td>197.51 ns<\/td>\n<td>2.9225 ns<\/td>\n<td>2.5907 ns<\/td>\n<td>0.0787<\/td>\n<td>&#8212;<\/td>\n<td>&#8212;<\/td>\n<td>248 B<\/td>\n<\/tr>\n<tr>\n<td>AOTMapperToUser<\/td>\n<td>46.46 ns<\/td>\n<td>0.3530 ns<\/td>\n<td>0.3129 ns<\/td>\n<td>0.0686<\/td>\n<td>&#8212;<\/td>\n<td>&#8212;<\/td>\n<td>216 B<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u043a \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u043f\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0421\u0430\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434(\u0443\u043f\u0443\u0441\u043a\u0430\u044f \u043e\u0431\u0432\u044f\u0437\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u0434):<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private void Handle(OperationAnalysisContext context) {     var syntax = context.Operation.Syntax;     if (syntax is InvocationExpressionSyntax invocationSytax &amp;&amp;         invocationSytax.Expression is MemberAccessExpressionSyntax memberAccessSyntax &amp;&amp;         syntax.DescendantNodes().OfType&lt;GenericNameSyntax&gt;().FirstOrDefault() is GenericNameSyntax genericNameSyntax &amp;&amp;         genericNameSyntax.Identifier.ValueText == \"MapTo\")     {         var semanticModel = context.Compilation.GetSemanticModel(syntax.SyntaxTree);         var methodInformation = semanticModel.GetSymbolInfo(genericNameSyntax);         if (methodInformation.Symbol.ContainingAssembly.Name != CoreAssemblyName)         {             return;         }          var fromTypeInfo = semanticModel.GetTypeInfo(memberAccessSyntax.Expression);         var fromTypeName = fromTypeInfo.Type.ToDisplayString();          var typeSyntax = genericNameSyntax.TypeArgumentList.Arguments.First();         var toTypeInfo = semanticModel.GetTypeInfo(typeSyntax);         var toTypeName = toTypeInfo.Type.ToDisplayString();          var properties = ImmutableDictionary&lt;string, string&gt;.Empty             .Add(\"fromType\", fromTypeName)             .Add(\"toType\", toTypeName);          context.ReportDiagnostic(Diagnostic.Create(AOTMapperIsNotReadyDescriptor, genericNameSyntax.GetLocation(), properties));     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0442\u043e\u0442 \u043b\u0438 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0442\u0438\u043f \u0438\u0437 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u0437\u0432\u0430\u043d <code>MapTo&lt;&gt;<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0442 \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. <\/p>\n<p>  <\/p>\n<p>\u041e\u043d\u043e \u0443\u0436\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <code>AOTMapperCodeFixProvider<\/code>. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0438\u043f\u0430\u0445 \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e. \u041f\u043e\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432 <code>MapTo&lt;&gt;<\/code> \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>AOTMapperGenerator<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0442 \u043d\u0430\u043c \u0444\u0430\u0439\u043b \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434: <\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private async Task&lt;Document&gt; Handle(Diagnostic diagnostic, CodeFixContext context) {     var fromTypeName = diagnostic.Properties[\"fromType\"];     var toTypeName = diagnostic.Properties[\"toType\"];     var document = context.Document;      var semanticModel = await document.GetSemanticModelAsync();      var root = await diagnostic.Location.SourceTree.GetRootAsync();     var call = root.FindNode(diagnostic.Location.SourceSpan);     root = root.ReplaceNode(call, SyntaxFactory.IdentifierName($\"MapTo{toTypeName.Split('.').Last()}\"));      var pairs = ImmutableDictionary&lt;string, string&gt;.Empty         .Add(fromTypeName, toTypeName);      var generator = new AOTMapperGenerator(document.Project, semanticModel.Compilation);     generator.GenerateMappers(pairs, new[] { \"AOTMapper\", \"Mappers\" });      var newProject = generator.Project;     var documentInNewProject = newProject.GetDocument(document.Id);      return documentInNewProject.WithSyntaxRoot(root); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c <code>AOTMapperGenerator<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0444\u0430\u0439\u043b\u044b \u0441 \u043c\u0430\u043f\u0438\u043d\u0433\u0430\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0438\u043f\u0430\u043c\u0438.<br \/>  \u0421\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public void GenerateMappers(ImmutableDictionary&lt;string, string&gt; values, string[] outputNamespace) {     foreach (var value in values)     {         var fromSymbol = this.Compilation.GetTypeByMetadataName(value.Key);         var toSymbol = this.Compilation.GetTypeByMetadataName(value.Value);         var fromSymbolName = fromSymbol.ToDisplayString().Replace(\".\", \"\");         var toSymbolName = toSymbol.ToDisplayString().Replace(\".\", \"\");         var fileName = $\"{fromSymbolName}_To_{toSymbolName}\";          var source = this.GenerateMapper(fromSymbol, toSymbol, fileName);          this.Project = this.Project             .AddDocument($\"{fileName}.cs\", source)             .WithFolders(outputNamespace)             .Project;     } }  private string GenerateMapper(INamedTypeSymbol fromSymbol, INamedTypeSymbol toSymbol, string fileName) {     var fromProperties = fromSymbol.GetAllMembers()         .OfType&lt;IPropertySymbol&gt;()         .Where(o =&gt; (o.DeclaredAccessibility &amp; Accessibility.Public) &gt; 0)         .ToDictionary(o =&gt; o.Name, o =&gt; o.Type);      var toProperties = toSymbol.GetAllMembers()         .OfType&lt;IPropertySymbol&gt;()         .Where(o =&gt; (o.DeclaredAccessibility &amp; Accessibility.Public) &gt; 0)         .ToDictionary(o =&gt; o.Name, o =&gt; o.Type);          return $@\" public static class {fileName}Extentions  {{     public static {toSymbol.ToDisplayString()} MapTo{toSymbol.ToDisplayString().Split('.').Last()}(this {fromSymbol.ToDisplayString()} input)     {{         var output = new {toSymbol.ToDisplayString()}(); { toProperties     .Where(o =&gt; fromProperties.TryGetValue(o.Key, out var type) &amp;&amp; type == o.Value)     .Select(o =&gt; $\"        output.{o.Key} = input.{o.Key};\" )     .JoinWithNewLine() } { toProperties     .Where(o =&gt; !fromProperties.TryGetValue(o.Key, out var type) || type != o.Value)     .Select(o =&gt; $\"        output.{o.Key} = ; \/\/ missing property\")     .JoinWithNewLine() }         return output;     }} }} \"; }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"vyvody\">\u0412\u044b\u0432\u043e\u0434\u044b<\/h1>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u043f\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u044f\u043c\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0435\u0433\u043e \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0430. \u0412 \u043f\u043b\u0430\u043d\u0430\u0445 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0434\u043b\u044f \u0438\u043c\u0435\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043a\u0443\u0434\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0442\u0438\u043f\u0430\u0445. \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u044f \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u043e \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044e \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u043f\u043e\u043a\u0430 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438\u0442\u044c \u0441 \u044d\u0442\u0438\u043c.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \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\/459771\/\"> https:\/\/habr.com\/ru\/post\/459771\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/455952\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Roslyn. \u0422\u043e\u0433\u0434\u0430\u0448\u043d\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u0445\u043e\u0447\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435. <\/p>\n<p>  <\/p>\n<p>\u0418 \u0442\u0430\u043a, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 <a href=\"https:\/\/github.com\/AutoMapper\/AutoMapper\">AutoMapper<\/a> \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/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-292002","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292002","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=292002"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292002\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}