Browse Source

Updated Ref<T> to include implicit conversion operators

pull/1/head
Anairkoen Schno 5 years ago
parent
commit
19c19df8bf
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      IPA.Loader/Utilities/Ref.cs

+ 21
- 1
IPA.Loader/Utilities/Ref.cs View File

@ -49,12 +49,32 @@ namespace IPA.Utilities
_value = reference; _value = reference;
} }
/// <summary>
/// Converts to referenced type, returning the stored reference.
/// </summary>
/// <param name="self">the object to be de-referenced</param>
/// <returns>the value referenced by the object</returns>
public static implicit operator T(Ref<T> self)
{
return self.Value;
}
/// <summary>
/// Converts a value T to a reference to that object. Will overwrite the reference in the left hand expression if there is one.
/// </summary>
/// <param name="toConvert">the value to wrap in the Ref</param>
/// <returns>the Ref wrapping the value</returns>
public static implicit operator Ref<T>(T toConvert)
{
return new Ref<T>(toConvert);
}
/// <summary> /// <summary>
/// Throws error if one was set. /// Throws error if one was set.
/// </summary> /// </summary>
public void Verify() public void Verify()
{ {
if (Error != null) throw new Exception("Found error", Error);
if (Error != null) throw Error;
} }
} }


Loading…
Cancel
Save