From e29b7cbafdf5a4d62ac8b9ac4e838c3dc8fa4e89 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 16:58:29 +0100 Subject: [PATCH] - add GBaseKey class that is only settable once --- GBase/GBaseKey.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 GBase/GBaseKey.cs diff --git a/GBase/GBaseKey.cs b/GBase/GBaseKey.cs new file mode 100644 index 0000000..00ab036 --- /dev/null +++ b/GBase/GBaseKey.cs @@ -0,0 +1,30 @@ +// Author: Gockner, Simon +// Created: 2020-11-13 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; + +namespace GBase +{ + public class GBaseKey + { + private int _key = -1; + private bool _isSet; + + public int Key + { + get => _key; + internal set + { + if (_isSet) + throw new InvalidOperationException("Key is already set."); + + _key = value; + _isSet = true; + } + } + + public override string ToString() => $"{Key}"; + public static implicit operator int(GBaseKey key) => key.Key; + } +} \ No newline at end of file