| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | |
| | | 4 | | namespace NanoCLang.Entities { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides a class for structure fields inside structure definitions. |
| | | 7 | | /// </summary> |
| | | 8 | | public class StructField : Base, IEquatable<StructField?> { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Creates a new instance of a structure field from a <paramref name="name"/> and the accompanying <paramref na |
| | | 11 | | /// </summary> |
| | 62 | 12 | | public StructField(string name, BlockType binding) { |
| | 31 | 13 | | Name = name; |
| | 31 | 14 | | Binding = binding; |
| | 31 | 15 | | } |
| | | 16 | | /// <summary> |
| | | 17 | | /// Name of the structure field. |
| | | 18 | | /// </summary> |
| | 214 | 19 | | public string Name { get; } |
| | | 20 | | /// <summary> |
| | | 21 | | /// Binding that belongs to the field. |
| | | 22 | | /// </summary> |
| | 198 | 23 | | public BlockType Binding { get; } |
| | | 24 | | /// <inheritdoc/> |
| | 6 | 25 | | public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) { |
| | 6 | 26 | | yield return Name; |
| | 12 | 27 | | if (args.SpaceBeforeBindingAssignment) yield return " "; |
| | 6 | 28 | | yield return "="; |
| | 12 | 29 | | if (args.SpaceAfterBindingAssignment) yield return " "; |
| | 408 | 30 | | foreach (var tk in Binding.Tokens(args)) yield return tk; |
| | 6 | 31 | | } |
| | | 32 | | #region Equality checks |
| | | 33 | | /// <inheritdoc/> |
| | 0 | 34 | | public override bool Equals(object? obj) => Equals(obj as StructField); |
| | | 35 | | /// <inheritdoc/> |
| | 6 | 36 | | public bool Equals(StructField? other) => !(other is null) && Name == other.Name && EqualityComparer<BlockType>. |
| | | 37 | | /// <inheritdoc/> |
| | 0 | 38 | | public override int GetHashCode() => HashCode.Combine(Name, Binding); |
| | | 39 | | /// <inheritdoc/> |
| | 0 | 40 | | public static bool operator ==(StructField? left, StructField? right) => EqualityComparer<StructField?>.Default. |
| | | 41 | | /// <inheritdoc/> |
| | 0 | 42 | | public static bool operator !=(StructField? left, StructField? right) => !(left == right); |
| | | 43 | | #endregion |
| | | 44 | | } |
| | | 45 | | } |