public static TTo Convert <TFrom, TTo>(this TFrom?obj, Func <TFrom, TTo> some, Func <TTo> none) where TFrom : class { return(obj != null ? some(obj) : none()); }
/// <inheritdoc/> public override TTo Convert(TFrom?value) { if (toIsValueType && !value.HasValue) { throw new ArgumentNullException("value"); } return(BaseConverter.Convert(value.GetValueOrDefault())); }
public TTo Map(TFrom?from, IObjectMapperResolver resolver) { if (from == null) { return(null); } return(resolver.GetMapper <TFrom, TTo>().Map(from.Value, resolver)); }
public TTo Map(TFrom?from, IObjectMapperResolver resolver) { if (from == null) { throw new ArgumentNullException("`from` is null but `to` does not allow null."); } return(resolver.GetMapper <TFrom, TTo>().Map(from.Value, resolver)); }
public static TTo?ConvertEnum <TFrom, TTo>(TFrom?from) where TTo : struct where TFrom : struct { if (from.HasValue) { return(ConvertEnum <TFrom, TTo>(from.Value)); } return(null); }
public static ValueOption <TFrom> op_Implicit <TFrom>(TFrom?value) where TFrom : struct { if ((!value.HasValue)) { return(ValueOption <TFrom> .None()); } else { return(ValueOption <TFrom> .Some(value.Value)); } }
internal static TTo?MapNullableEnum <TFrom, TTo>(TFrom?otherEnum) where TTo : struct where TFrom : struct { if (otherEnum == null) { return(null); } return(UtilitiesInternal.MapEnum <TFrom, TTo>(otherEnum.Value)); }
/// <inheritdoc/> public override TTo?Convert(TFrom?value) { if (value.HasValue) { return(BaseConverter.Convert(value.Value)); } else { return(null); } }
public static option <TFrom> op_Implicit <TFrom>(TFrom?value) where TFrom : struct { if (!value.HasValue) { return(option <TFrom> .None._N_constant_object); } else { return(new option <TFrom> .Some(value.Value)); } }
/// <summary> /// Method that will be called by <see cref="Convert(object, Type, object, CultureInfo)"/>. /// </summary> /// <param name="value">Value to be converted from <see cref="TFrom"/> to <see cref="TTo"/>.</param> /// <returns>An object of type <see cref="TTo"/>.</returns> public abstract TTo?ConvertFrom(TFrom?value);
protected static IResult <TReturned, NonEmptyString> TryCreateInt(TFrom?value, NonEmptyString field, Func <TFrom, IResult <TReturned, NonEmptyString> > createFunc) { return(value == null?GetFailResult((NonEmptyString)"{0} can't be null", field) : createFunc(value.Value)); }
private static ReferenceCountedDisposable <TTo>?TryAddReferenceImpl <TFrom, TTo>(TFrom?target, StrongBox <int> referenceCount, out CreateResult result) where TFrom : class, IDisposable where TTo : class, IDisposable { lock (referenceCount) { if (referenceCount.Value == 0) { // The target is already disposed, and cannot be reused result = CreateResult.Disposed; return(null); } if (target == null) { // The current reference has been disposed, so even though it isn't disposed yet we don't have a // reference to the target result = CreateResult.Disposed; return(null); } if (!(target is TTo castedTarget)) { // The target cannot be casted to type TTo result = CreateResult.NotCastable; return(null); } checked { referenceCount.Value++; } // Must return a new instance, in order for the Dispose operation on each individual instance to // be idempotent. result = CreateResult.Success; return(new ReferenceCountedDisposable <TTo>(castedTarget, referenceCount)); } }