SHARE
TWEET

Untitled

a guest Jun 16th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#@ template debug="false" hostspecific="false" language="C#" #>
  2. <#@ assembly name="System.Core" #>
  3. <#@ import namespace="System.Linq" #>
  4. <#@ import namespace="System.Text" #>
  5. <#@ import namespace="System.Collections.Generic" #>
  6. <#@ output extension=".cs" #>
  7. /*
  8.  * ==== THIS IS A GENERATED FILE ====
  9.  *  ===       DO NOT EDIT!       ===
  10.  *
  11.  * See the EntityIdentifiers.tt file
  12.  * In order to add a new Identifier, add the Identifier's name to the
  13.  * "identifiers" array in Identifiers.tt file
  14.  *
  15.  * SEE ALSO:
  16.  * IdentifierModelBinders.tt
  17.  * IdentifierJsonConverters.tt
  18.  */
  19. using System;
  20.  
  21. namespace Solid.DataType
  22. {
  23. <#
  24.     var identifiers = new []
  25.     {
  26.         "Person",
  27.         "Country",
  28.         "Address"
  29.     };
  30.     foreach (var identifier in identifiers){
  31.     var identifierName = identifier + "Identifier";
  32. #>
  33.     // Generated via EntityIdentifiers.tt
  34.     public /*readonly*/ partial struct <#= identifierName #> : IEquatable<<#= identifierName #>>
  35.     {
  36.         private const int UndefinedId = default(int);
  37.         private readonly int _value;
  38.  
  39.         public static readonly <#= identifierName #> Undefined = new <#= identifierName #>();
  40.  
  41.         public <#= identifierName #>(int value) { _value = value; }
  42.  
  43.         [System.Diagnostics.Contracts.Pure]
  44.         public bool IsDefined => _value != <#= identifierName #>.UndefinedId;
  45.  
  46.         #region Equality
  47.         [System.Diagnostics.Contracts.Pure]
  48.         public bool Equals(<#= identifierName #> other) => _value == other._value;
  49.  
  50.         [System.Diagnostics.Contracts.Pure]
  51.         public override bool Equals(object obj)
  52.         {
  53.             return obj is <#= identifierName #> other && Equals(other);
  54.         }
  55.  
  56.         [System.Diagnostics.Contracts.Pure]
  57.         public override int GetHashCode() => _value;
  58.  
  59.         [System.Diagnostics.Contracts.Pure]
  60.         public static bool operator ==(<#= identifierName #> left, <#= identifierName #> right)
  61.         {
  62.             return left.Equals(right);
  63.         }
  64.  
  65.         [System.Diagnostics.Contracts.Pure]
  66.         public static bool operator !=(<#= identifierName #> left, <#= identifierName #> right)
  67.         {
  68.             return !left.Equals(right);
  69.         }
  70.  
  71.         #endregion
  72.  
  73.         #region Conversion
  74.         [System.Diagnostics.Contracts.Pure]
  75.         public static explicit operator int(<#= identifierName #> id) => id._value;
  76.  
  77.         [System.Diagnostics.Contracts.Pure]
  78.         public static explicit operator <#= identifierName #>(int id) => new <#= identifierName #>(id);
  79.  
  80.         [System.Diagnostics.Contracts.Pure]
  81.         public static bool TryParse(string candidate, out <#= identifierName #> value)
  82.         {
  83.             if (int.TryParse(candidate, out int idValue))
  84.             {
  85.                 value = new <#= identifierName #>(idValue);
  86.                 return true;
  87.             }
  88.             value = <#= identifierName #>.Undefined;
  89.             return false;
  90.         }
  91.         #endregion
  92.  
  93.         /// <summary>Used to convert the Id to a string</summary>
  94.         /// <remarks>Used in serialisation</remarks>
  95.         [System.Diagnostics.Contracts.Pure]
  96.         public override string ToString() => $"{_value}";
  97.     }
  98.  
  99. <#
  100.     }
  101. #>
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top