A game framework written with osu! in mind.
at master 37 lines 1.0 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5 6namespace osu.Framework.Bindables 7{ 8 public class NonNullableBindable<T> : Bindable<T> 9 where T : class 10 { 11 public NonNullableBindable(T defaultValue) 12 { 13 if (defaultValue == null) 14 throw new ArgumentNullException(nameof(defaultValue)); 15 16 Value = Default = defaultValue; 17 } 18 19 private NonNullableBindable() 20 { 21 } 22 23 public override T Value 24 { 25 get => base.Value; 26 set 27 { 28 if (value == null) 29 throw new ArgumentNullException(nameof(value), $"Cannot set {nameof(Value)} of a {nameof(NonNullableBindable<T>)} to null."); 30 31 base.Value = value; 32 } 33 } 34 35 protected override Bindable<T> CreateInstance() => new NonNullableBindable<T>(); 36 } 37}