{"id":267776,"date":"2015-11-09T12:34:02","date_gmt":"2015-11-09T09:34:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=267776"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=267776","title":{"rendered":"\u041a\u0430\u043a \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c DTO?"},"content":{"rendered":"<p>       \u0417\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u043e\u043b\u0442\u043e\u0440\u0430 \u043c\u0435\u0441\u044f\u0446\u0430 \u043c\u043d\u0435 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 backend-\u043e\u043c \u0442\u0440\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0430 XML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438; \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c DTO-\u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0448\u043b\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 XML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0431\u044b\u043b\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u0432\u0437\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0433\u043d\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0443\u0442\u0438\u043b\u0438\u0442\u0443 xsd, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f\u044b, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f\\\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0435, \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0443\u043c\u0430\u0442\u044c \u0443\u0436\u0435 \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c, \u0442\u0430\u043a \u0447\u0442\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u043d\u0430\u0447\u0430\u043b\u0438 \u0441\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u044b\u0441\u043b\u0438, \u043a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043b\u0438\u0431\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0438 \u0442\u043e, \u0438 \u0434\u0440\u0443\u0433\u043e\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">TLDR<\/b><\/p>\n<div class=\"spoiler_text\">\u0414\u043b\u044f \u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0431\u0435\u0440\u0435\u043c DTO-\u043f\u043e\u043b\u0443\u0444\u0430\u0431\u0440\u0438\u043a\u0430\u0442 \u0438\u0437 xsd, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432-\u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0430\u0445\u0430\u0440\u0443 (implicit operators), <s>\u043a\u043b\u0430\u0434\u0435\u043c \u0432 \u043c\u0438\u043a\u0440\u043e\u0432\u043e\u043b\u043d\u043e\u0432\u043a\u0443 \u043d\u0430 30 \u043c\u0438\u043d\u0443\u0442<\/s>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.   <\/div>\n<\/div>\n<p>  \u0421\u043f\u0435\u0440\u0432\u0430 \u0437\u0430\u0433\u043e\u043d\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u0435\u0446 XML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0443\u0442\u0438\u043b\u0438\u0442\u0443 xsd. DTO-\u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 xsd.exe \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">\/\/ \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435: \u0432\u0435\u0440\u0441\u0438\u044f xsd [System.SerializableAttribute] [XmlTypeAttribute(AnonymousType = true)] public class DtoProduct { \tprivate string productidfield; \tprivate string productnamefield; \tprivate string productpricefield; \t\/*...*\/  \t[XmlElement] \tpublic string productid \t{ \t\tget{return this.productidfield;} \t\tset{this.productidfield = value;} \t}  \t[XmlElement] \tpublic string productname \t{ \t\tget{return this.productnamefield;} \t\tset{this.productnamefield = value;} \t}  \t[XmlElement] \tpublic string productprice \t{ \t\tget{return this.productpricefield;} \t\tset{this.productpricefield = value;} \t}\t } <\/code><\/pre>\n<p>  \u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441\u043e \u0441\u0442\u0438\u043b\u0435\u043c (\u043b\u0435\u0447\u0438\u0442\u0441\u044f \u0420\u0435\u0448\u0430\u0440\u043f\u0435\u0440\u043e\u043c \u0438\\\u0438\u043b\u0438 Ctrl+H), \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0442\u0438\u043f\u0430\u043c\u0438: \u0434\u043b\u044f price \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 decimal, \u0434\u043b\u044f Id \u2014 long. \u0417\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0430\u0448\u0438\u0445 DTO \u0441\u043a\u0430\u0436\u0443\u0442 \u043d\u0430\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e, \u043b\u0438\u0431\u043e \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0436\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u043c \u0441\u0433\u043e\u0440\u0435\u0442\u044c \u0432 \u0430\u0434\u0443. \u0412\u043d\u0435\u0441\u0435\u043c \u043f\u0440\u0430\u0432\u043a\u0438, \u0437\u0430\u043e\u0434\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u044f \u0438\u043c\u0435\u043d\u0430 \u043a \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443.<\/p>\n<pre><code class=\"cs\">[System.SerializableAttribute] [XmlTypeAttribute(AnonymousType = true)] public class DtoProduct {\t \tprivate decimal _productPrice; \t \t\/\/...  \t[XmlElement(&quot;productprice&quot;)] \tpublic decimal ProductPrice \t{ \t\tget{return _productPrice;} \t\tset{_productPrice = value;} \t}\t } <\/code><\/pre>\n<p>  \u0423\u0436\u0435 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 (\u0434\u0435)\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439: \u0443 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u043e \u044d\u0442\u043e \u0434\u043b\u044f \u0434\u0430\u0442 \u0438 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041f\u043b\u044e\u0441, \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0438\u043f\u044b (guid, code, mail).<\/p>\n<p>  \u0414\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 null \u2014 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f (\u0447\u0438\u0442\u0430\u0439, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u043d\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f). Double, int, bool \u2014 \u044d\u0442\u043e \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (Value Types), \u0438 \u043e\u043d\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null; \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 int \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (\u0447\u0438\u0442\u0430\u0439, \u0435\u0441\u043b\u0438 int \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u043d\u0435 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f 0). \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432\u0440\u0435\u0434\u0430 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u043e\u0435 \u0432 \u043a\u043e\u0434\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c. <\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043c \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b (\u0434\u0435)\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c Money (decimal), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u00abd.dd\u00bb (\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u00ab\u0442\u043e\u0447\u043a\u0430\u00bb, \u0434\u0432\u0430 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f). \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 XmlMoneyWrapper, \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 IXmlSerializable.<\/p>\n<pre><code class=\"cs\">public class XmlMoneyWrapper : IXmlSerializable { \tpublic decimal Value { get; set; } \/\/ \u0422\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435  \tpublic override string ToString() \t{\t\t \t\treturn Value.ToString(&quot;0.00&quot;, CultureInfo.InvariantCulture); \t}\t  \t#region IXmlSerializable Members \tpublic XmlSchema GetSchema() { return null; } \tpublic void ReadXml(XmlReader reader)  \t{ \t\tstring value = reader.ReadString(); \t\t\/\/ TODO change to TryParse? \t\ttry \t\t{ \t\t\tValue = Decimal.Parse(value, \t\t\t\tnew NumberFormatInfo \t\t\t\t{ \t\t\t\t\tNumberDecimalSeparator = &quot;.&quot; \t\t\t\t}); \t\t} \t\tcatch (Exception exc) \t\t{ \t\t\tString err = String.Format(&quot;Can't deserialize string {0} to decimal. Expected number decimal separator is dot \\&quot;.\\&quot;&quot;, value); \t\t\tthrow new SerializationException(err, exc); \t\t} \t\treader.Read(); \t} \tpublic void WriteXml(XmlWriter writer) \t{ \t\twriter.WriteString(ToString());  \t} \t#endregion } <\/code><\/pre>\n<p>  \u0418 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u0448 DTO:<\/p>\n<pre><code class=\"cs\">[System.SerializableAttribute] [XmlTypeAttribute(AnonymousType = true)] public class DtoProduct { \tprivate XmlMoneyWrapper _productPrice;  \t\/\/...  \t[XmlElement(&quot;productprice&quot;)] \tpublic XmlMoneyWrapper ProductPrice \/\/ \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0430\u0432\u0442\u043e\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u043a\u043e\u0434 \t{ \t\tget { return _productPrice; } \t\tset { _productPrice = value; } \t} } <\/code><\/pre>\n<p>  \u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 Nullable \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a null; \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f DTO \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 DTO \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043b\u0430\u0441\u044c. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 if(product.ProductPrice &gt; 10.00) \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 if(product.ProductPrice.Value &gt; 10.00). <\/p>\n<p>  \u0412\u044b\u0432\u043e\u0434: \u043d\u0443\u0436\u043d\u043e <s>\u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u043b\u043e\u0436\u0435\u043a \u0441\u0430\u0445\u0430\u0440\u0430<\/s> \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432.<\/p>\n<pre><code class=\"cs\">public static implicit operator XmlMoneyWrapper(decimal arg) \/\/ decimal to XmlMoneyWrapper { \tXmlMoneyWrapper res = new XmlMoneyWrapper { Value = arg }; \treturn res; } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"cs\">public static implicit operator decimal (XmlMoneyWrapper arg) \/\/ XmlMoneyWrapper to decimal  { \treturn arg.Value; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u043d\u043e\u0432\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432\u0438\u0434\u0430 if(product.ProductPrice &gt; 10.00). \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0430 (\u0438 \u043a\u043e\u043c\u043c\u0438\u0442\u0430) \u0441\u0442\u043e\u0438\u0442 \u0432\u043d\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043e \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0448 DTO \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u0440\u043e implicit operators, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. <s>\u0412\u0435\u0434\u044c \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u043d\u0435 \u043f\u043e\u0432\u044b\u043f\u0435\u043d\u0434\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0438\u0447\u0435\u0439?<\/s><\/p>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0438\u043f\u044b \u043d\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u0441 \u043d\u0435\u044f\u0432\u043d\u044b\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b: \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438<\/p>\n<pre><code class=\"cs\">public static implicit operator XmlLimitedStringWrapper(string arg) <\/code><\/pre>\n<p>  \u043d\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u043e \u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">[System.SerializableAttribute] [XmlTypeAttribute(AnonymousType = true)] public class DtoProduct {\t \tprivate readonly XmlLimitedStringWrapper _productName = new XmlLimitedStringWrapper(16); \/\/ Create string with maxLength = 16. \t\/\/ ...                  \/\/ Max symbols: 16. \t[XmlElement(&quot;productname&quot;)] \tpublic string ProductName \t{ \t\tget{return _productName = _productName.Value;} \t\tset{_productName.Value = value;} \t}\t } <\/code><\/pre>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u044d\u0442\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0441\u044b\u0440\u043e\u0439 DTO-\u043f\u043e\u043b\u0443\u0444\u0430\u0431\u0440\u0438\u043a\u0430\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442. \u0412\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043a\u0440\u044b\u0442\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432 \u0441\u0432\u043e\u0435\u043c \u043a\u043e\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u043f\u043e \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f\u043c) \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0447\u0443\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0447\u0435\u043c \u0440\u0430\u043d\u044c\u0448\u0435. \u0417\u0430 \u0441\u0447\u0435\u0442 Nullable \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c\u0441\u044f \u0442\u0440\u0430\u0444\u0444\u0438\u043a. \u041d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0441\u0435\u0445 XmlPrimitiveTypeWrapper \u0442\u0438\u043f\u043e\u0432 \u0443\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u043d\u044f (\u0441 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c). \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043e\u0431\u0435\u0440\u0442\u043a\u0438, \u0431\u043b\u0430\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u043d\u0438 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>  \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435: \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/270473\/\"> http:\/\/habrahabr.ru\/post\/270473\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0417\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u043e\u043b\u0442\u043e\u0440\u0430 \u043c\u0435\u0441\u044f\u0446\u0430 \u043c\u043d\u0435 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 backend-\u043e\u043c \u0442\u0440\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0430 XML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438; \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c DTO-\u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0448\u043b\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 XML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0431\u044b\u043b\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u0432\u0437\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0433\u043d\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0443\u0442\u0438\u043b\u0438\u0442\u0443 xsd, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f\u044b, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f\\\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0435, \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0443\u043c\u0430\u0442\u044c \u0443\u0436\u0435 \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c, \u0442\u0430\u043a \u0447\u0442\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u043d\u0430\u0447\u0430\u043b\u0438 \u0441\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u044b\u0441\u043b\u0438, \u043a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043b\u0438\u0431\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0438 \u0442\u043e, \u0438 \u0434\u0440\u0443\u0433\u043e\u0435.  <\/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-267776","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267776","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=267776"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267776\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}