{"id":336107,"date":"2022-07-24T21:00:08","date_gmt":"2022-07-24T21:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336107"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336107","title":{"rendered":"<span>\u041d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043a\u043e\u0434\u0433\u0435\u043d\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/5e7\/82c\/307\/5e782c3076947b6d506f02edac627061.jpg\" width=\"3380\" height=\"1178\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5e7\/82c\/307\/5e782c3076947b6d506f02edac627061.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 C# \u0434\u0430\u0432\u043d\u043e \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e. \u041d\u043e \u043f\u043e\u043a\u043e\u043f\u0430\u0432\u0448\u0438\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043e\u0431\u0449\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0430\u0439\u0434\u043e\u0432. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0441\u0430\u0439\u0442\u0443 \u043c\u0441, \u0437\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435. \u041d\u043e, \u0443\u0432\u044b, \u0442\u0430\u043c \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u0430, \u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435  \u043f\u043e\u0431\u0435\u0434\u0430 \u043d\u0430\u0434 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<h2>\u0423\u0441\u043b\u043e\u0432\u0438\u044f<\/h2>\n<p>\u0415\u0441\u0442\u044c \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u0432 \u0443\u0437\u043a\u0438\u0445 \u043a\u0440\u0443\u0433\u0430\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/vknet\/vk\" rel=\"noopener noreferrer nofollow\">VkNet<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0432 \u0441\u0432\u043e\u0435\u043c \u043a\u043e\u0434\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 <code>FromJson<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code class=\"cs\">public static Model FromJson(VkResponse response)<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u0430\u0440\u0441\u0438\u0442 \u043c\u043e\u0434\u0435\u043b\u044c <code>VkResponse<\/code> \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0418 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<br \/> \u0418 \u0442\u043e\u0433\u043e:<\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 partial \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u0440\u0435\u0434\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u0436\u0435 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c<code>JsonProperty<\/code><\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0438\u043f\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 partial \u043a\u043b\u0430\u0441\u0441 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 IDE Rider<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430<\/h2>\n<p>\u0412\u044b\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0435\u0431\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 VKNet \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 VkNet.Generators \u0442\u0438\u043f\u0430 Class Library <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0d5\/873\/de2\/0d5873de2982d3ed91f464446c6c5244.png\" width=\"328\" height=\"178\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d5\/873\/de2\/0d5873de2982d3ed91f464446c6c5244.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <code>TargetFramework<\/code> \u0443 \u043d\u043e\u0432\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043a\u0430\u043a <code>netstandard2.0<\/code>\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438: <code>Microsoft.CodeAnalysis.Analyzers<\/code>, <code>Microsoft.CodeAnalysis.CSharp<\/code>.<\/p>\n<p>\u0410 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 VkNet) \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"xml\">&lt;ItemGroup> &lt;ProjectReference Include=\"..\\VkNet.Generators\\VkNet.Generators.csproj\" OutputItemType=\"Analyzer\"   ReferenceOutputAssembly=\"false\"  \/> &lt;\/ItemGroup><\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430.<br \/>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 <code>VkNet.Generators<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>[Generator]<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432 \u043d\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>ISourceGenerator<\/code>.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<br \/>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Execute<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">System.Diagnostics.Debugger.Launch(); Debug.WriteLine(\"generator start\");<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u0440\u0430\u0439\u0434\u0435\u0440, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0431\u0438\u043b\u0434\u0430.<br \/>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043b\u0435\u0437\u0435\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0442\u044b\u043a\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443 <strong>Set Rider as the default debugger<\/strong>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6da\/756\/8f8\/6da7568f8b536f536259516da824b136.png\" width=\"1095\" height=\"520\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6da\/756\/8f8\/6da7568f8b536f536259516da824b136.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u043e\u0438\u0441\u043a \u043d\u0443\u0436\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h2>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Execute<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>Context<\/code> \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043e \u0432\u044b\u0448\u0435, \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u044b \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"cs\">var models = context.Compilation .SyntaxTrees .SelectMany(syntaxTree => syntaxTree.GetRoot().DescendantNodes()) .Where(x => x is ClassDeclarationSyntax) .Cast&lt;ClassDeclarationSyntax>() .Where(GetPartialModels) .Where(GetSerializableModels) .Where(NotHaveMethodFromJson) .ToImmutableList();<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432 6\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0443\u0436\u0435 \u0441 \u043d\u0438\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0435 \u043a \u043d\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e partial \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/strong> <\/p>\n<pre><code class=\"cs\">private static bool GetPartialModels(ClassDeclarationSyntax x) { return x.Modifiers.Any(m => m.ValueText == \"partial\"); }<\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b:<\/strong><\/p>\n<pre><code class=\"cs\">classDeclarationSyntax.AttributeLists.First().Attributes.Any(x => x.Name.ToString() == \"Serializable\");<\/code><\/pre>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 FromJson \u043c\u0435\u0442\u043e\u0434\u0430:<\/strong><\/p>\n<pre><code class=\"cs\">classDeclarationSyntax.Members .Any(x =>   (x.Kind() == SyntaxKind.MethodDeclaration  &amp;&amp; ((MethodDeclarationSyntax) x).Identifier.ValueText != \"FromJSON\"));<\/code><\/pre>\n<h2>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0442\u0431\u0443\u0442\u043e\u043c <code>JsonProperty<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0442\u0438\u043f, \u0438\u043c\u044f, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430.<\/p>\n<p><strong>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430:<\/strong><\/p>\n<pre><code class=\"cs\">var properties = model.Members.OfType&lt;PropertyDeclarationSyntax>();<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<p><strong>\u0418\u043c\u044f:<\/strong><\/p>\n<pre><code class=\"cs\">var propertyName = property.Identifier.ValueText;<\/code><\/pre>\n<p><strong>\u0422\u0438\u043f:<\/strong><\/p>\n<pre><code class=\"cs\">var propertyType = property.Type.ToString();<\/code><\/pre>\n<p><strong>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 JsonProperty:<\/strong><\/p>\n<pre><code class=\"cs\">var attributeArgument = property.AttributeLists.First() .Attributes.First(x => x.Name.ToString() == \"JsonProperty\") .ArgumentList?.Arguments.First() .Expression.DescendantTokens() .First() .Text.Replace(\"\\\"\", string.Empty);<\/code><\/pre>\n<h2>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043b\u0430 \u043c\u0435\u0442\u043e\u0434\u0430<\/h2>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435, \u0442\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435<\/p>\n<p>\u0418\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 = \u041e\u0442\u0432\u0435\u0442 \u0412\u043a [\u041a\u043b\u044e\u0447]<br \/>\u0414\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d:<\/p>\n<pre><code class=\"cs\">const string PropertyDeclaration = \"{0} = response[\\\"{1}\\\"],\";<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f, \u0438 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432:<\/p>\n<pre><code class=\"cs\">const string PropertyReadonlyCollectionWithLambda = \"{0} = response[\\\"{1}\\\"].ToReadOnlyCollectionOf&lt;{2}>(x => x),\";  const string PropertyVkCollection = \"{0} = response[\\\"{1}\\\"].ToVkCollectionOf&lt;{2}>(x => x),\";<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u043e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0438\u0445 \u0442\u0438\u043f \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<pre><code class=\"cs\">Count = response[\"count\"], Items = response[\"items\"].ToReadOnlyCollectionOf&lt;Conversation>(), Profiles = response[\"profiles\"].ToReadOnlyCollectionOf&lt;User>(), Groups = response[\"groups\"].ToReadOnlyCollectionOf&lt;Group>(),<\/code><\/pre>\n<h2>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/h2>\n<p>\u0414\u043b\u044f \u0442\u0435\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"cs\">\/\/ Auto-generated code using System; using VkNet.Utils;  namespace {0} {{     public  partial class {1}     {{         public static {2} FromJson(VkResponse response) {{ return new {3} {{ {4} }}; }}     }} }}<\/code><\/pre>\n<p>\u0418\u0437 \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f <code>ClassDeclarationSyntax<\/code> \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f <code>namespace,<\/code> \u0430 \u0442\u0430\u043a \u0436\u0435 3 \u0440\u0430\u0437\u0430 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0442\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u043d\u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u044d\u0442\u0430\u043f\u0435.<\/p>\n<pre><code class=\"cs\">string.Format(ClassDefinition, namespaceName, className, className, className, fieldDeclaration)<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0442\u0435\u043b\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\"> \/\/ Auto-generated code using System; using VkNet.Utils;  namespace VkNet.Model {     public  partial class ConversationResult     {         public static ConversationResult FromJson(VkResponse response) {           return new ConversationResult           {             Count = response[\"count\"],             Items = response[\"items\"].ToReadOnlyCollectionOf&lt;Conversation>(),             Profiles = response[\"profiles\"].ToReadOnlyCollectionOf&lt;User>(),             Groups = response[\"groups\"].ToReadOnlyCollectionOf&lt;Group>(),           }; }     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u0432 \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\">context.AddSource(model.Identifier.ValueText + \".g.cs\",classDeclaration);<\/code><\/pre>\n<h2>\u0422\u0435\u0441\u0442<\/h2>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 10 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>FromJson<\/code>.<\/p>\n<pre><code class=\"cs\">string nspace = \"Model\";  var assembly = Assembly.GetAssembly(typeof(VkApi)); var types = assembly.GetTypes(); var classes = types.Where(x => x.IsClass  &amp;&amp; x.Namespace != null  &amp;&amp; x.Namespace.Contains(nspace));  var count = classes .Select(@class => @class.GetMethods(BindingFlags.Public|BindingFlags.Static) .Where(x => x.Name.StartsWith(\"FromJson\"))) .Count(methods => methods.Any());  count.Should().BeEqualTo(10);<\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>\u041a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0430 C# \u043e\u0447\u0435\u043d\u044c \u043c\u043e\u0449\u043d\u044b\u0439, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u044d\u0442\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0438\u0437 ms \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p> \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0430\u0441\u0438\u0431\u043e @<a href=\"https:\/\/habr.com\/ru\/users\/fornever\/\" rel=\"noopener noreferrer nofollow\">ForNeVeR<\/a>.  <\/p>\n<p> \u0418 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e \u0421# \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/t.me\/DotNetRuChat\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u0410 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/vknet\/vk\/blob\/develop\/VkNet.Generators\/SourceGenerators\/FromJsonGenerator.cs\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0439\u043b\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u0431\u0441\u0443\u0436\u0434\u0430\u044f \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u043e\u0439 \u043e\u043d \u0437\u0430\u0434\u0430\u043b \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441:<\/p>\n<p><sub>\u0412\u043e\u0442 \u044d\u0442\u0430 \u0432\u043e\u0442 \u0432\u0441\u044f \u0448\u043d\u044f\u0433\u0430 \u0437\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u0430, \u0435\u0441\u043b\u0438 \u0442\u0430\u043c \u0443\u0436\u0435 \u043d\u044c\u044e\u0442\u043e\u043d\u0441\u043e\u0432\u0442?<\/sub><\/p>\n<p><sub>\u041d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e JsonConvert.Deserialize(response)?<\/sub><\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442, \u0433\u0440\u0443\u0441\u0442\u0435\u043d \u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0435\u043d:<br \/>1) \u0422\u0430\u043a \u0441\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438<br \/>2) \u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440 \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0442 VkResponse \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0441\u0438\u043b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<br \/>3) \u042d\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u0435\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><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\/678690\/\"> https:\/\/habr.com\/ru\/post\/678690\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 C# \u0434\u0430\u0432\u043d\u043e \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e. \u041d\u043e \u043f\u043e\u043a\u043e\u043f\u0430\u0432\u0448\u0438\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043e\u0431\u0449\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0430\u0439\u0434\u043e\u0432. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0441\u0430\u0439\u0442\u0443 \u043c\u0441, \u0437\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435. \u041d\u043e, \u0443\u0432\u044b, \u0442\u0430\u043c \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u0430, \u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435  \u043f\u043e\u0431\u0435\u0434\u0430 \u043d\u0430\u0434 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<h2>\u0423\u0441\u043b\u043e\u0432\u0438\u044f<\/h2>\n<p>\u0415\u0441\u0442\u044c \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u0432 \u0443\u0437\u043a\u0438\u0445 \u043a\u0440\u0443\u0433\u0430\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/vknet\/vk\" rel=\"noopener noreferrer nofollow\">VkNet<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0432 \u0441\u0432\u043e\u0435\u043c \u043a\u043e\u0434\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 <code>FromJson<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code class=\"cs\">public static Model FromJson(VkResponse response)<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u0430\u0440\u0441\u0438\u0442 \u043c\u043e\u0434\u0435\u043b\u044c <code>VkResponse<\/code> \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0418 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<br \/> \u0418 \u0442\u043e\u0433\u043e:<\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 partial \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u0440\u0435\u0434\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u0436\u0435 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c<code>JsonProperty<\/code><\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0438\u043f\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 partial \u043a\u043b\u0430\u0441\u0441 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 IDE Rider<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430<\/h2>\n<p>\u0412\u044b\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0435\u0431\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 VKNet \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 VkNet.Generators \u0442\u0438\u043f\u0430 Class Library <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <code>TargetFramework<\/code> \u0443 \u043d\u043e\u0432\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043a\u0430\u043a <code>netstandard2.0<\/code>\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438: <code>Microsoft.CodeAnalysis.Analyzers<\/code>, <code>Microsoft.CodeAnalysis.CSharp<\/code>.<\/p>\n<p>\u0410 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 VkNet) \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"xml\">&lt;ItemGroup> &lt;ProjectReference Include=\"..\\VkNet.Generators\\VkNet.Generators.csproj\" OutputItemType=\"Analyzer\"   ReferenceOutputAssembly=\"false\"  \/> &lt;\/ItemGroup><\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430.<br \/>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 <code>VkNet.Generators<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>[Generator]<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432 \u043d\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>ISourceGenerator<\/code>.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<br \/>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Execute<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">System.Diagnostics.Debugger.Launch(); Debug.WriteLine(\"generator start\");<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u0440\u0430\u0439\u0434\u0435\u0440, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0431\u0438\u043b\u0434\u0430.<br \/>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043b\u0435\u0437\u0435\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0442\u044b\u043a\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443 <strong>Set Rider as the default debugger<\/strong>.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u043e\u0438\u0441\u043a \u043d\u0443\u0436\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h2>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Execute<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>Context<\/code> \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043e \u0432\u044b\u0448\u0435, \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u044b \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"cs\">var models = context.Compilation .SyntaxTrees .SelectMany(syntaxTree => syntaxTree.GetRoot().DescendantNodes()) .Where(x => x is ClassDeclarationSyntax) .Cast&lt;ClassDeclarationSyntax>() .Where(GetPartialModels) .Where(GetSerializableModels) .Where(NotHaveMethodFromJson) .ToImmutableList();<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432 6\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0443\u0436\u0435 \u0441 \u043d\u0438\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0435 \u043a \u043d\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e partial \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/strong> <\/p>\n<pre><code class=\"cs\">private static bool GetPartialModels(ClassDeclarationSyntax x) { return x.Modifiers.Any(m => m.ValueText == \"partial\"); }<\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b:<\/strong><\/p>\n<pre><code class=\"cs\">classDeclarationSyntax.AttributeLists.First().Attributes.Any(x => x.Name.ToString() == \"Serializable\");<\/code><\/pre>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 FromJson \u043c\u0435\u0442\u043e\u0434\u0430:<\/strong><\/p>\n<pre><code class=\"cs\">classDeclarationSyntax.Members .Any(x =>   (x.Kind() == SyntaxKind.MethodDeclaration  &amp;&amp; ((MethodDeclarationSyntax) x).Identifier.ValueText != \"FromJSON\"));<\/code><\/pre>\n<h2>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0442\u0431\u0443\u0442\u043e\u043c <code>JsonProperty<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0442\u0438\u043f, \u0438\u043c\u044f, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430.<\/p>\n<p><strong>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430:<\/strong><\/p>\n<pre><code class=\"cs\">var properties = model.Members.OfType&lt;PropertyDeclarationSyntax>();<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<p><strong>\u0418\u043c\u044f:<\/strong><\/p>\n<pre><code class=\"cs\">var propertyName = property.Identifier.ValueText;<\/code><\/pre>\n<p><strong>\u0422\u0438\u043f:<\/strong><\/p>\n<pre><code class=\"cs\">var propertyType = property.Type.ToString();<\/code><\/pre>\n<p><strong>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 JsonProperty:<\/strong><\/p>\n<pre><code class=\"cs\">var attributeArgument = property.AttributeLists.First() .Attributes.First(x => x.Name.ToString() == \"JsonProperty\") .ArgumentList?.Arguments.First() .Expression.DescendantTokens() .First() .Text.Replace(\"\\\"\", string.Empty);<\/code><\/pre>\n<h2>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043b\u0430 \u043c\u0435\u0442\u043e\u0434\u0430<\/h2>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435, \u0442\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435<\/p>\n<p>\u0418\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 = \u041e\u0442\u0432\u0435\u0442 \u0412\u043a [\u041a\u043b\u044e\u0447]<br \/>\u0414\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d:<\/p>\n<pre><code class=\"cs\">const string PropertyDeclaration = \"{0} = response[\\\"{1}\\\"],\";<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f, \u0438 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432:<\/p>\n<pre><code class=\"cs\">const string PropertyReadonlyCollectionWithLambda = \"{0} = response[\\\"{1}\\\"].ToReadOnlyCollectionOf&lt;{2}>(x => x),\";  const string PropertyVkCollection = \"{0} = response[\\\"{1}\\\"].ToVkCollectionOf&lt;{2}>(x => x),\";<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u043e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0438\u0445 \u0442\u0438\u043f \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<pre><code class=\"cs\">Count = response[\"count\"], Items = response[\"items\"].ToReadOnlyCollectionOf&lt;Conversation>(), Profiles = response[\"profiles\"].ToReadOnlyCollectionOf&lt;User>(), Groups = response[\"groups\"].ToReadOnlyCollectionOf&lt;Group>(),<\/code><\/pre>\n<h2>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/h2>\n<p>\u0414\u043b\u044f \u0442\u0435\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"cs\">\/\/ Auto-generated code using System; using VkNet.Utils;  namespace {0} {{     public  partial class {1}     {{         public static {2} FromJson(VkResponse response) {{ return new {3} {{ {4} }}; }}     }} }}<\/code><\/pre>\n<p>\u0418\u0437 \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f <code>ClassDeclarationSyntax<\/code> \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f <code>namespace,<\/code> \u0430 \u0442\u0430\u043a \u0436\u0435 3 \u0440\u0430\u0437\u0430 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0442\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u043d\u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u044d\u0442\u0430\u043f\u0435.<\/p>\n<pre><code class=\"cs\">string.Format(ClassDefinition, namespaceName, className, className, className, fieldDeclaration)<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0442\u0435\u043b\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\"> \/\/ Auto-generated code using System; using VkNet.Utils;  namespace VkNet.Model {     public  partial class ConversationResult     {         public static ConversationResult FromJson(VkResponse response) {           return new ConversationResult           {             Count = response[\"count\"],             Items = response[\"items\"].ToReadOnlyCollectionOf&lt;Conversation>(),             Profiles = response[\"profiles\"].ToReadOnlyCollectionOf&lt;User>(),             Groups = response[\"groups\"].ToReadOnlyCollectionOf&lt;Group>(),           }; }     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u0432 \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\">context.AddSource(model.Identifier.ValueText + \".g.cs\",classDeclaration);<\/code><\/pre>\n<h2>\u0422\u0435\u0441\u0442<\/h2>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 10 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>FromJson<\/code>.<\/p>\n<pre><code class=\"cs\">string nspace = \"Model\";  var assembly = Assembly.GetAssembly(typeof(VkApi)); var types = assembly.GetTypes(); var classes = types.Where(x => x.IsClass  &amp;&amp; x.Namespace != null  &amp;&amp; x.Namespace.Contains(nspace));  var count = classes .Select(@class => @class.GetMethods(BindingFlags.Public|BindingFlags.Static) .Where(x => x.Name.StartsWith(\"FromJson\"))) .Count(methods => methods.Any());  count.Should().BeEqualTo(10);<\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>\u041a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0430 C# \u043e\u0447\u0435\u043d\u044c \u043c\u043e\u0449\u043d\u044b\u0439, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u044d\u0442\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0438\u0437 ms \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p> \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0430\u0441\u0438\u0431\u043e @<a href=\"https:\/\/habr.com\/ru\/users\/fornever\/\" rel=\"noopener noreferrer nofollow\">ForNeVeR<\/a>.  <\/p>\n<p> \u0418 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e \u0421# \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/t.me\/DotNetRuChat\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u0410 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/vknet\/vk\/blob\/develop\/VkNet.Generators\/SourceGenerators\/FromJsonGenerator.cs\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0439\u043b\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u0431\u0441\u0443\u0436\u0434\u0430\u044f \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u043e\u0439 \u043e\u043d \u0437\u0430\u0434\u0430\u043b \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441:<\/p>\n<p><sub>\u0412\u043e\u0442 \u044d\u0442\u0430 \u0432\u043e\u0442 \u0432\u0441\u044f \u0448\u043d\u044f\u0433\u0430 \u0437\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u0430, \u0435\u0441\u043b\u0438 \u0442\u0430\u043c \u0443\u0436\u0435 \u043d\u044c\u044e\u0442\u043e\u043d\u0441\u043e\u0432\u0442?<\/sub><\/p>\n<p><sub>\u041d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e JsonConvert.Deserialize(response)?<\/sub><\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442, \u0433\u0440\u0443\u0441\u0442\u0435\u043d \u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0435\u043d:<br \/>1) \u0422\u0430\u043a \u0441\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438<br \/>2) \u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440 \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0442 VkResponse \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0441\u0438\u043b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<br \/>3) \u042d\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u0435\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><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\/678690\/\"> https:\/\/habr.com\/ru\/post\/678690\/<\/a><br \/><\/br><\/br><\/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-336107","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336107","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=336107"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336107\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}