{"id":284183,"date":"2017-03-30T15:55:05","date_gmt":"2017-03-30T11:55:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284183"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284183","title":{"rendered":"\u0428\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u00bb \u0432 C#"},"content":{"rendered":"<blockquote><p>\u00ab\u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u00bb \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0432\u0438\u0434\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0431\u0443\u043b\u0435\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p><\/blockquote>\n<p>  \u042f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0447\u0442\u0435\u043d\u0438\u044f <a href=\"https:\/\/www.amazon.com\/Domain-Driven-Design-Tackling-Complexity-Software\/dp\/0321125215\">DDD \u042d\u0432\u0430\u043d\u0441\u0430<\/a>. \u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 <a href=\"https:\/\/habrahabr.ru\/post\/171559\/\">\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430<\/a> \u0438 <a href=\"https:\/\/habrahabr.ru\/post\/260771\/\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439\u00bb \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u044b\u0441\u044f\u0447\u0438 \u0440\u0430\u0437\u043c\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0440\u043e\u0432\u043d\u044b\u043c \u0441\u043b\u043e\u0435\u043c \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">public interface ISpecification {     bool IsSatisfiedBy(object candidate); } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0427\u0442\u043e \u0441 \u043d\u0438\u043c \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a C#?<\/h4>\n<p>  <\/p>\n<ol>\n<li>\u0415\u0441\u0442\u044c <code>Expression&lt;Func&lt;T, bool&gt;&gt;<\/code> \u0438 <code>Func&lt;T, bool&gt;&gt;<\/code>, \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 IsSatisfiedBy<\/li>\n<li>\u0415\u0441\u0442\u044c Extension-\u043c\u0435\u0442\u043e\u0434\u044b. <a href=\"https:\/\/habrahabr.ru\/users\/alexanderzaytsev\/\" class=\"user_link\">alexanderzaytsev<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0438\u0445 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<br \/> \n<pre><code class=\"cs\">public class UserQueryExtensions  {   public static IQueryable&lt;User&gt; WhereGroupNameIs(this IQueryable&lt;User&gt; users, strin name)   {       return users.Where(u =&gt; u.GroupName == name);   } } <\/code><\/pre>\n<p>  <\/li>\n<li>\u0410 \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/nblumhardt.com\/archives\/implementing-the-specification-pattern-via-linq\/\">\u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043d\u0430\u0434 LINQ<\/a>:<br \/> \n<pre><code class=\"cs\">public abstract class Specification&lt;T&gt; {   public bool IsSatisfiedBy(T item)   {     return SatisfyingElementsFrom(new[] { item }.AsQueryable()).Any();   }     public abstract IQueryable&lt;T&gt; SatisfyingElementsFrom(IQueryable&lt;T&gt; candidates); } <\/code><\/pre>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<h4>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0432 C# \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u0435\u0441\u044f\u0442\u0438\u043b\u0435\u0442\u043d\u0435\u0439 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 \u043c\u0438\u0440\u0430 Java \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/h4>\n<p><a name=\"habracut\"><\/a><br \/>  \u041c\u044b \u0440\u0435\u0448\u0438\u043b\u0438, \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cs\">public interface IQueryableSpecification&lt;T&gt;     where T: class  {     IQueryable&lt;T&gt; Apply(IQueryable&lt;T&gt; query); }  public interface IQueryableOrderBy&lt;T&gt; {     IOrderedQueryable&lt;T&gt; Apply(IQueryable&lt;T&gt; queryable); }  public static bool Satisfy&lt;T&gt;(this T obj, Func&lt;T, bool&gt; spec) =&gt; spec(obj);  public static bool SatisfyExpresion&lt;T&gt;(this T obj, Expression&lt;Func&lt;T, bool&gt;&gt; spec) =&gt; spec.AsFunc()(obj);  public static bool IsSatisfiedBy&lt;T&gt;(this Func&lt;T, bool&gt; spec, T obj) =&gt; spec(obj);  public static bool IsSatisfiedBy&lt;T&gt;(this Expression&lt;Func&lt;T, bool&gt;&gt; spec, T obj) =&gt; spec.AsFunc()(obj);  public static IQueryable&lt;T&gt; Where&lt;T&gt;(this IQueryable&lt;T&gt; source, IQueryableSpecification&lt;T&gt; spec)     where T : class     =&gt; spec.Apply(source); <\/code><\/pre>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 <code>Func&lt;T, bool&gt;<\/code>?<\/h4>\n<p>  \u041e\u0442 <code>Func<\/code> \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a <code>Expression<\/code>. \u0427\u0430\u0449\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 <code>Expression&lt;Func&lt;T, bool&gt;&gt;<\/code>?<\/h4>\n<p>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u043e\u0442 <code>Expression<\/code> \u043a <code>Func<\/code>, \u043d\u0430\u043f\u0440\u043e\u0442\u0438\u0432, \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u0435\u043d: <code>var func = expression.Compile()<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u043a\u0430 Expression \u2014 <a href=\"https:\/\/habrahabr.ru\/post\/313394\/\">\u043e\u0442\u043d\u044e\u0434\u044c \u043d\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430<\/a>. \u0421\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u0430\u044f \u0441\u0431\u043e\u0440\u043a\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0440\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0434\u0432\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u2013 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435.<\/p>\n<p>  \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u044d\u0442\u0438 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u0432\u0435\u043b\u0438 \u043d\u0430 \u043c\u044b\u0441\u043b\u044c, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0439 <code>IQueryable<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 fluent interface. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b Where \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043a\u043e\u0434\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c, \u0441\u043b\u043e\u0432\u043d\u043e \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 LINQ-\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439.<\/p>\n<p>  \u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443\u044f\u0441\u044c \u044d\u0442\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438:  <\/p>\n<pre><code class=\"cs\">public static IOrderedQueryable&lt;T&gt; OrderBy&lt;T&gt;(this IQueryable&lt;T&gt; source, IQueryableOrderBy&lt;T&gt; spec)     where T : class     =&gt; spec.Apply(source);  public interface IQueryableOrderBy&lt;T&gt; {     IOrderedQueryable&lt;T&gt; Apply(IQueryable&lt;T&gt; queryable); } <\/code><\/pre>\n<p>  \u0422\u043e\u0433\u0434\u0430, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 <a href=\"https:\/\/weblogs.asp.net\/scottgu\/dynamic-linq-part-1-using-the-linq-dynamic-query-library\">Dynamic Linq<\/a> \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e <s>\u043e\u0441\u043e\u0431\u043e\u0439 \u0443\u043b\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0433\u0438\u0438<\/s> <code>Reflection<\/code>, \u043c\u043e\u0436\u043d\u043e \u0432 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0447\u0435\u0433\u043e-\u0443\u0433\u043e\u0434\u043d\u043e. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 <code>AutoSpec<\/code> \u0438 \u0442\u0438\u043f\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e. \u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 <code>AutoSpec<\/code> \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043a <code>Queryable <\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e.  <\/p>\n<pre><code class=\"cs\">public class AutoSpec&lt;TProjection&gt; : IPaging, ILinqSpecification&lt;TProjection&gt;, ILinqOrderBy&lt;TProjection&gt;     where TProjection : class, IHasId {     public virtual IQueryable&lt;TProjection&gt; Apply(IQueryable&lt;TProjection&gt; query) =&gt; GetType()         .GetPublicProperties()         .Where(x =&gt; typeof(TProjection).GetPublicProperties().Any(y =&gt; x.Name == y.Name))         .Aggregate(query, (current, next) =&gt;         {             var val = next.GetValue(this);             if (val == null) return current;             return current.Where(next.PropertyType == typeof(string)                    ? $&quot;{next.Name}.StartsWith(@0)&quot;                    : $&quot;{next.Name}=@0&quot;, val);         });      IOrderedQueryable&lt;TProjection&gt; ILinqOrderBy&lt;TProjection&gt;.Apply(IQueryable&lt;TProjection&gt; queryable)         =&gt; !string.IsNullOrEmpty(OrderBy) ? queryable.OrderBy(OrderBy) : queryable.OrderBy(x =&gt; x.Id); }  <\/code><\/pre>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/325280\/\"> https:\/\/habrahabr.ru\/post\/325280\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<blockquote><p>\u00ab\u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u00bb \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0432\u0438\u0434\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0431\u0443\u043b\u0435\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p><\/blockquote>\n<p>  \u042f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0447\u0442\u0435\u043d\u0438\u044f <a href=\"https:\/\/www.amazon.com\/Domain-Driven-Design-Tackling-Complexity-Software\/dp\/0321125215\">DDD \u042d\u0432\u0430\u043d\u0441\u0430<\/a>. \u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 <a href=\"https:\/\/habrahabr.ru\/post\/171559\/\">\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430<\/a> \u0438 <a href=\"https:\/\/habrahabr.ru\/post\/260771\/\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439\u00bb \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u044b\u0441\u044f\u0447\u0438 \u0440\u0430\u0437\u043c\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0440\u043e\u0432\u043d\u044b\u043c \u0441\u043b\u043e\u0435\u043c \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">public interface ISpecification {     bool IsSatisfiedBy(object candidate); } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0427\u0442\u043e \u0441 \u043d\u0438\u043c \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a C#?<\/h4>\n<p>  <\/p>\n<ol>\n<li>\u0415\u0441\u0442\u044c <code>Expression&lt;Func&lt;T, bool&gt;&gt;<\/code> \u0438 <code>Func&lt;T, bool&gt;&gt;<\/code>, \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 IsSatisfiedBy<\/li>\n<li>\u0415\u0441\u0442\u044c Extension-\u043c\u0435\u0442\u043e\u0434\u044b. <a href=\"https:\/\/habrahabr.ru\/users\/alexanderzaytsev\/\" class=\"user_link\">alexanderzaytsev<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0438\u0445 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<br \/> \n<pre><code class=\"cs\">public class UserQueryExtensions  {   public static IQueryable&lt;User&gt; WhereGroupNameIs(this IQueryable&lt;User&gt; users, strin name)   {       return users.Where(u =&gt; u.GroupName == name);   } } <\/code><\/pre>\n<p>  <\/li>\n<li>\u0410 \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/nblumhardt.com\/archives\/implementing-the-specification-pattern-via-linq\/\">\u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043d\u0430\u0434 LINQ<\/a>:<br \/> \n<pre><code class=\"cs\">public abstract class Specification&lt;T&gt; {   public bool IsSatisfiedBy(T item)   {     return SatisfyingElementsFrom(new[] { item }.AsQueryable()).Any();   }     public abstract IQueryable&lt;T&gt; SatisfyingElementsFrom(IQueryable&lt;T&gt; candidates); } <\/code><\/pre>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<h4>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0432 C# \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u0435\u0441\u044f\u0442\u0438\u043b\u0435\u0442\u043d\u0435\u0439 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 \u043c\u0438\u0440\u0430 Java \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/h4>\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-284183","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284183","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=284183"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284183\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}