Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#@ template debug="false" hostspecific="false" language="C#" #>
- <#@ assembly name="System.Core" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Text" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#@ output extension=".cs" #>
- /*
- * ==== THIS IS A GENERATED FILE ====
- * === DO NOT EDIT! ===
- *
- * See the EntityIdentifiers.tt file
- * In order to add a new Identifier, add the Identifier's name to the
- * "identifiers" array in Identifiers.tt file
- *
- * SEE ALSO:
- * IdentifierModelBinders.tt
- * IdentifierJsonConverters.tt
- */
- using System;
- namespace Solid.DataType
- {
- <#
- var identifiers = new []
- {
- "Person",
- "Country",
- "Address"
- };
- foreach (var identifier in identifiers){
- var identifierName = identifier + "Identifier";
- #>
- // Generated via EntityIdentifiers.tt
- public /*readonly*/ partial struct <#= identifierName #> : IEquatable<<#= identifierName #>>
- {
- private const int UndefinedId = default(int);
- private readonly int _value;
- public static readonly <#= identifierName #> Undefined = new <#= identifierName #>();
- public <#= identifierName #>(int value) { _value = value; }
- [System.Diagnostics.Contracts.Pure]
- public bool IsDefined => _value != <#= identifierName #>.UndefinedId;
- #region Equality
- [System.Diagnostics.Contracts.Pure]
- public bool Equals(<#= identifierName #> other) => _value == other._value;
- [System.Diagnostics.Contracts.Pure]
- public override bool Equals(object obj)
- {
- return obj is <#= identifierName #> other && Equals(other);
- }
- [System.Diagnostics.Contracts.Pure]
- public override int GetHashCode() => _value;
- [System.Diagnostics.Contracts.Pure]
- public static bool operator ==(<#= identifierName #> left, <#= identifierName #> right)
- {
- return left.Equals(right);
- }
- [System.Diagnostics.Contracts.Pure]
- public static bool operator !=(<#= identifierName #> left, <#= identifierName #> right)
- {
- return !left.Equals(right);
- }
- #endregion
- #region Conversion
- [System.Diagnostics.Contracts.Pure]
- public static explicit operator int(<#= identifierName #> id) => id._value;
- [System.Diagnostics.Contracts.Pure]
- public static explicit operator <#= identifierName #>(int id) => new <#= identifierName #>(id);
- [System.Diagnostics.Contracts.Pure]
- public static bool TryParse(string candidate, out <#= identifierName #> value)
- {
- if (int.TryParse(candidate, out int idValue))
- {
- value = new <#= identifierName #>(idValue);
- return true;
- }
- value = <#= identifierName #>.Undefined;
- return false;
- }
- #endregion
- /// <summary>Used to convert the Id to a string</summary>
- /// <remarks>Used in serialisation</remarks>
- [System.Diagnostics.Contracts.Pure]
- public override string ToString() => $"{_value}";
- }
- <#
- }
- #>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement