Created
November 16, 2018 14:21
-
-
Save atifaziz/f59593c4bf444998870acf82dc1c74b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Copyright (c) 2018 Atif Aziz. All rights reserved. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the "Software"), | |
// to deal in the Software without restriction, including without limitation | |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
// and/or sell copies of the Software, and to permit persons to whom the | |
// Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in | |
// all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
// DEALINGS IN THE SOFTWARE. | |
// | |
#endregion | |
// ReSharper disable once PartialTypeWithSinglePart | |
static partial class Extensions | |
{ | |
public static bool MapOut<T>(this T? nullable, out T value) where T : struct | |
{ | |
if (!nullable.HasValue) | |
{ | |
value = default; | |
return false; | |
} | |
value = nullable.Value; | |
return true; | |
} | |
public static bool MapOut<T1, T2>(this (T1, T2)? nullable, out T1 v1, out T2 v2) | |
{ | |
if (!nullable.MapOut(out var couple)) | |
{ | |
v1 = default; | |
v2 = default; | |
return false; | |
} | |
(v1, v2) = couple; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment