{"id":309471,"date":"2020-09-04T15:00:39","date_gmt":"2020-09-04T15:00:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309471"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309471","title":{"rendered":"Enum \u0438 switch, \u0438 \u0447\u0442\u043e \u0441 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0442\u0430\u043a"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/517864\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/37\/3l\/3f\/373l3ftvet9kahlfvcrb7j7xvcg.jpeg\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u044b\u043b\u043e \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 enum \u0438 \u043f\u043e\u0442\u043e\u043c \u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u0447\u0430\u0441\u044b \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u043c\u0435\u0441\u0442\u0430 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 case, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c ArgumentOutOfRangeException \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f? <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"ideya\">\u0418\u0434\u0435\u044f<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 switch \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0442\u043e\u0433\u0434\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f \u043e\u0442 \u043d\u0438\u0445! <\/p>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 switch \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c visitor.<\/p>\n<p>  <\/p>\n<h2 id=\"primer-1\">\u041f\u0440\u0438\u043c\u0435\u0440 1<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e API \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0442\u0438\u043f, \u0430 \u0434\u0430\u043b\u0435\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0444\u0430\u0439\u043b <strong>DocumentType.cs<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public enum DocumentType {     Invoice,     PrepaymentAccount }  public interface IDocumentVisitor&lt;out T&gt; {     T VisitInvoice();     T VisitPrepaymentAccount(); }  public static class DocumentTypeExt {     public static T Accept&lt;T&gt;(this DocumentType self, IDocumentVisitor&lt;T&gt; visitor)     {         switch (self)         {             case DocumentType.Invoice:                 return visitor.VisitInvoice();             case DocumentType.PrepaymentAccount:                 return visitor.VisitPrepaymentAccount();             default:                 throw new ArgumentOutOfRangeException(nameof(self), self, null);         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0434\u0430, \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435, \u0447\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0434\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u043c \u0434\u043b\u044f .Net \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c <del>\u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442<\/del> \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c visitor \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 <strong>DatabaseSearchVisitor.cs<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class DatabaseSearchVisitor : IDocumentVisitor&lt;IDocument&gt; {     private ApiId _id;     private Database _db;      public DatabaseSearchVisitor(ApiId id, Database db)     {         _id = id;         _db = db;     }      public IDocument VisitInvoice() =&gt; _db.SearchInvoice(_id);     public IDocument VisitPrepaymentAccount() =&gt; _db.SearchPrepaymentAccount(_id); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u043f\u043e\u0442\u043e\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public void UpdateStatus(ApiDoc doc) {     var searchVisitor = new DatabaseSearchVisitor(doc.Id, _db);      var databaseDocument = doc.Type.Accept(searchVisitor);      databaseDocument.Status = doc.Status;      _db.SaveChanges(); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"primer-2\">\u041f\u0440\u0438\u043c\u0435\u0440 2<\/h2>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public enum PurseEventType {     Increase,     Decrease,     Block,     Unlock }  public sealed class PurseEvent {     public PurseEventType Type { get; }     public string Json { get; }      public PurseEvent(PurseEventType type, string json)     {         Type = type;         Json = json;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0422\u043e\u0433\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c visitor:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public interface IPurseEventTypeVisitor&lt;out T&gt; {     T VisitIncrease();     T VisitDecrease();     T VisitBlock();     T VisitUnlock(); }  public sealed class PurseEventTypeNotificationVisitor : IPurseEventTypeVisitor&lt;Missing&gt; {     private readonly INotificationManager _notificationManager;     private readonly PurseEventParser _eventParser;     private readonly PurseEvent _event;      public PurseEventTypeNotificationVisitor(PurseEvent @event, PurseEventParser eventParser, INotificationManager notificationManager)     {         _notificationManager = notificationManager;         _event = @event;         _eventParser = eventParser;     }      public Missing VisitIncrease() =&gt; Missing.Value;      public Missing VisitDecrease() =&gt; Missing.Value;      public Missing VisitBlock()     {         var blockEvent = _eventParser.ParseBlock(_event);         _notificationManager.NotifyBlockPurseEvent(blockEvent);         return Missing.Value;     }      public Missing VisitUnlock()     {         var blockEvent = _eventParser.ParseUnlock(_event);         _notificationManager.NotifyUnlockPurseEvent(blockEvent);         return Missing.Value;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0438\u043f\u043e\u043c Missing \u0438\u0437 System.Reflection \u0438\u043b\u0438 \u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0438\u043f Unit. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0441\u044f \u0431\u044b Result, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public void SendNotification(PurseEvent @event) {     var notificationVisitor = new PurseEventTypeNotificationVisitor(@event, _eventParser, _notificationManager);     @event.Type.Accept(notificationVisitor); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"dopolnenie\">\u0414\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<h3 id=\"esli-nuzhno-bystree\">\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 visitor \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0422\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public static T Accept&lt;TVisitor, T&gt;(this DocumentType self, in TVisitor visitor)     where TVisitor : IDocumentVisitor&lt;T&gt;     {         switch (self)         {             case DocumentType.Invoice:                 return visitor.VisitInvoice();             case DocumentType.PrepaymentAccount:                 return visitor.VisitPrepaymentAccount();             default:                 throw new ArgumentOutOfRangeException(nameof(self), self, null);         }     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c visitor \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c, \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u043d\u044f\u0435\u043c class \u043d\u0430 struct.<\/p>\n<p>  <\/p>\n<p>\u0418 \u0441\u0430\u043c \u043a\u043e\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public void UpdateStatus(ApiDoc doc) {     var searchVisitor = new DatabaseSearchVisitor(doc.Id, _db);      var databaseDocument = doc.Type.Accept&lt;DatabaseSearchVisitor, IDocument&gt;(searchVisitor);      databaseDocument.Status = doc.Status;      _db.SaveChanges(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 generic, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0442\u043e\u0447\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0441\u0430\u043c\u043e\u043c\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 <del>\u0445\u043e\u0447\u0435\u0442<\/del> \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>  <\/p>\n<h3 id=\"chitabelnost-i-in-place-realizaciya\">\u0427\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 in-place \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0442\u043e \u0447\u0430\u0441\u0442\u043e visitor \u2014 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e \u0438 \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 <strong>match<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public static T Match&lt;T&gt;(this DocumentType self, Func&lt;T&gt; invoiceCase, Func&lt;T&gt; prepaymentAccountCase) {     var visitor = new FuncVisitor&lt;T&gt;(invoiceCase, prepaymentCase);     return self.Accept&lt;FuncVisitor&lt;T&gt;, T&gt;(visitor); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c <strong>FuncVisitor<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public readonly struct FuncVisitor&lt;T&gt; : IDocumentVisitor&lt;T&gt; {     private readonly Func&lt;T&gt; _invoiceCase;     private readonly Func&lt;T&gt; _prepaymentAccountCase;      public FuncVisitor(Func&lt;T&gt; invoiceCase, Func&lt;T&gt; prepaymentAccountCase)     {         _invoiceCase = invoiceCase;         _prepaymentAccountCase = prepaymentAccountCase;     }      public T VisitInvoice() =&gt; _invoiceCase();     public T VisitPrepaymentAccount() =&gt; _prepaymentAccountCase(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>match<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public void UpdateStatus(ApiDoc doc) {     var databaseDocument = doc.Type.Match(         () =&gt; _db.SearchInvoice(doc.Id),         () =&gt; _db.SearchPrepaymentAccount(doc.Id)     );      databaseDocument.Status = doc.Status;      _db.SaveChanges(); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"itog\">\u0418\u0442\u043e\u0433<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 enum \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435. <\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0441\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442 \u043d\u0430\u043c, \u0433\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0437\u0430\u0431\u044b\u0442\u043e\u0433\u043e case \u0432 switch.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0441\u0435\u0440\u0435\u0431\u0440\u044f\u043d\u0430\u044f \u043f\u0443\u043b\u044f, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 enum.<\/p>\n<p>  <\/p>\n<h2 id=\"ssylki\">\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/blog.ploeh.dk\/2018\/06\/25\/visitor-as-a-sum-type\/\">https:\/\/blog.ploeh.dk\/2018\/06\/25\/visitor-as-a-sum-type\/<\/a><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Unit_type\">https:\/\/en.wikipedia.org\/wiki\/Unit_type<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/fsharp\/language-reference\/results\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/fsharp\/language-reference\/results<\/a><\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/517864\/\"> https:\/\/habr.com\/ru\/post\/517864\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/517864\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/37\/3l\/3f\/373l3ftvet9kahlfvcrb7j7xvcg.jpeg\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u044b\u043b\u043e \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 enum \u0438 \u043f\u043e\u0442\u043e\u043c \u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u0447\u0430\u0441\u044b \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u043c\u0435\u0441\u0442\u0430 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 case, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c ArgumentOutOfRangeException \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f? <\/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-309471","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309471","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=309471"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309471\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}