From 19c19df8bf3798374f4397d5d38bdbfaa1fe8a4e Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Fri, 21 Dec 2018 13:44:57 -0600 Subject: [PATCH] Updated Ref to include implicit conversion operators --- IPA.Loader/Utilities/Ref.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/IPA.Loader/Utilities/Ref.cs b/IPA.Loader/Utilities/Ref.cs index 933bcb04..f710ad6a 100644 --- a/IPA.Loader/Utilities/Ref.cs +++ b/IPA.Loader/Utilities/Ref.cs @@ -49,12 +49,32 @@ namespace IPA.Utilities _value = reference; } + /// + /// Converts to referenced type, returning the stored reference. + /// + /// the object to be de-referenced + /// the value referenced by the object + public static implicit operator T(Ref self) + { + return self.Value; + } + + /// + /// Converts a value T to a reference to that object. Will overwrite the reference in the left hand expression if there is one. + /// + /// the value to wrap in the Ref + /// the Ref wrapping the value + public static implicit operator Ref(T toConvert) + { + return new Ref(toConvert); + } + /// /// Throws error if one was set. /// public void Verify() { - if (Error != null) throw new Exception("Found error", Error); + if (Error != null) throw Error; } }