Skip to content

Commit

Permalink
Use auto property
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Jun 5, 2024
1 parent 18d2814 commit 12bdbfe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
10 changes: 4 additions & 6 deletions QRCoder/PayloadGenerator/SwissQrCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public SwissQrCode(Iban iban, Currency currency, Contact creditor, Reference ref
/// </summary>
public class AdditionalInformation
{
private readonly string _trailer;
private readonly string? _unstructuredMessage, _billInformation;

/// <summary>
Expand All @@ -97,7 +96,7 @@ public AdditionalInformation(string? unstructuredMessage = null, string? billInf
throw new SwissQrCodeAdditionalInformationException("Unstructured message and bill information must be shorter than 141 chars in total/combined.");
_unstructuredMessage = unstructuredMessage;
_billInformation = billInformation;
_trailer = "EPD";
Trailer = "EPD";
}

/// <summary>
Expand All @@ -113,7 +112,7 @@ public AdditionalInformation(string? unstructuredMessage = null, string? billInf
/// <summary>
/// Gets the trailer.
/// </summary>
public string Trailer => _trailer;
public string Trailer { get; }


/// <summary>
Expand Down Expand Up @@ -154,7 +153,6 @@ public SwissQrCodeAdditionalInformationException(string message, Exception inner
/// </summary>
public class Reference
{
private readonly ReferenceType _referenceType;
private readonly string? _reference;
private readonly ReferenceTextType? _referenceTextType;

Expand All @@ -166,7 +164,7 @@ public class Reference
/// <param name="referenceTextType">Type of the reference text (QR-reference or Creditor Reference)</param>
public Reference(ReferenceType referenceType, string? reference = null, ReferenceTextType? referenceTextType = null)
{
_referenceType = referenceType;
RefType = referenceType;
_referenceTextType = referenceTextType;

if (referenceType == ReferenceType.NON && reference != null)
Expand All @@ -188,7 +186,7 @@ public Reference(ReferenceType referenceType, string? reference = null, Referenc
/// <summary>
/// Gets the reference type.
/// </summary>
public ReferenceType RefType => _referenceType;
public ReferenceType RefType { get; }

/// <summary>
/// Gets the reference text.
Expand Down
35 changes: 17 additions & 18 deletions QRCoder/QRCodeGenerator/Polynom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ public partial class QRCodeGenerator
private struct Polynom : IDisposable
{
private PolynomItem[] _polyItems;
private int _length;

/// <summary>
/// Initializes a new instance of the <see cref="Polynom"/> struct with a specified number of initial capacity for polynomial terms.
/// </summary>
/// <param name="count">The initial capacity of the polynomial items list.</param>
public Polynom(int count)
{
_length = 0;
Count = 0;
_polyItems = RentArray(count);
}

Expand All @@ -30,22 +29,22 @@ public Polynom(int count)
/// </summary>
public void Add(PolynomItem item)
{
AssertCapacity(_length + 1);
_polyItems[_length++] = item;
AssertCapacity(Count + 1);
_polyItems[Count++] = item;
}

/// <summary>
/// Removes the polynomial term at the specified index.
/// </summary>
public void RemoveAt(int index)
{
if ((uint)index >= (uint)_length)
if ((uint)index >= (uint)Count)
throw new IndexOutOfRangeException();

if (index < _length - 1)
Array.Copy(_polyItems, index + 1, _polyItems, index, _length - index - 1);
if (index < Count - 1)
Array.Copy(_polyItems, index + 1, _polyItems, index, Count - index - 1);

_length--;
Count--;
}

/// <summary>
Expand All @@ -55,13 +54,13 @@ public PolynomItem this[int index]
{
get
{
if ((uint)index >= _length)
if ((uint)index >= Count)
ThrowIndexOutOfRangeException();
return _polyItems[index];
}
set
{
if ((uint)index >= _length)
if ((uint)index >= Count)
ThrowIndexOutOfRangeException();
_polyItems[index] = value;
}
Expand All @@ -79,24 +78,24 @@ private static void ThrowIndexOutOfRangeException()
/// <summary>
/// Gets the number of polynomial terms in the polynomial.
/// </summary>
public int Count => _length;
public int Count { get; private set; }

/// <summary>
/// Removes all polynomial terms from the polynomial.
/// </summary>
public void Clear()
{
_length = 0;
Count = 0;
}

/// <summary>
/// Clones the polynomial, creating a new instance with the same polynomial terms.
/// </summary>
public Polynom Clone()
{
var newPolynom = new Polynom(_length);
Array.Copy(_polyItems, newPolynom._polyItems, _length);
newPolynom._length = _length;
var newPolynom = new Polynom(Count);
Array.Copy(_polyItems, newPolynom._polyItems, Count);
newPolynom.Count = Count;
return newPolynom;
}

Expand All @@ -116,7 +115,7 @@ public void Sort(Func<PolynomItem, PolynomItem, int> comparer)
if (items == null)
throw new ObjectDisposedException(nameof(Polynom));

if (_length <= 1)
if (Count <= 1)
{
return; // Nothing to sort if the list is empty or contains only one element
}
Expand Down Expand Up @@ -152,7 +151,7 @@ void QuickSort(int left, int right)
QuickSort(i, right);
}

QuickSort(0, _length - 1);
QuickSort(0, Count - 1);
}

/// <summary>
Expand Down Expand Up @@ -298,7 +297,7 @@ public PolynumEnumerator(Polynom polynom)

public PolynomItem Current => _polynom[_index];

public bool MoveNext() => ++_index < _polynom._length;
public bool MoveNext() => ++_index < _polynom.Count;
}
}
}

0 comments on commit 12bdbfe

Please sign in to comment.