/// <summary> /// Try append new <see cref="ILine"/> to <paramref name="previous"/>. /// </summary> /// <param name="factory"></param> /// <param name="previous">(optional) previous part</param> /// <param name="a0"></param> /// <param name="a1"></param> /// <param name="a2"></param> /// <param name="line">result</param> /// <typeparam name="Intf"></typeparam> /// <typeparam name="A0"></typeparam> /// <typeparam name="A1"></typeparam> /// <typeparam name="A2"></typeparam> /// <returns>true if succeeded</returns> public static bool TryCreate <Intf, A0, A1, A2>(this ILineFactory factory, ILine previous, A0 a0, A1 a1, A2 a2, out Intf line) where Intf : ILine { if (factory == null) { line = default; return(false); } Intf result = default; if (factory is ILineFactory <Intf, A0, A1, A2> _casted && _casted.TryCreate(factory, previous, a0, a1, a2, out result)) { line = result; return(true); } ILineFactory <Intf, A0, A1, A2> casted; if (factory is ILineFactoryCastable castable && (casted = castable.Cast <Intf, A0, A1, A2>()) != null && casted.TryCreate(factory, previous, a0, a1, a2, out result)) { line = result; return(true); } ILine result_ = null; if (factory is ILineFactoryByArgument __casted && __casted.TryCreate(factory, previous, LineArgument.Create <Intf, A0, A1, A2>(a0, a1, a2), out result_) && result_ is Intf result__) { line = result__; return(true); } line = default; return(false); }
/// <summary> /// Append new <see cref="ILine"/> to <paramref name="previous"/>. /// </summary> /// <param name="factory"></param> /// <param name="a0"></param> /// <param name="a1"></param> /// <param name="a2"></param> /// <param name="previous">(optional) previous part</param> /// <typeparam name="Intf"></typeparam> /// <typeparam name="A0"></typeparam> /// <typeparam name="A1"></typeparam> /// <typeparam name="A2"></typeparam> /// <returns>Line</returns> /// <exception cref="LineException">If part could not append <typeparamref name="Intf"/></exception> public static Intf Create <Intf, A0, A1, A2>(this ILineFactory factory, ILine previous, A0 a0, A1 a1, A2 a2) where Intf : ILine { if (factory == null) { throw new LineException(previous, "Appender is not found."); } Intf result = default; if (factory is ILineFactory <Intf, A0, A1, A2> _casted && _casted.TryCreate(factory, previous, a0, a1, a2, out result)) { return(result); } ILineFactory <Intf, A0, A1, A2> casted; if (factory is ILineFactoryCastable castable && (casted = castable.Cast <Intf, A0, A1, A2>()) != null && casted.TryCreate(factory, previous, a0, a1, a2, out result)) { return(result); } ILine result_ = null; if (factory is ILineFactoryByArgument __casted && __casted.TryCreate(factory, previous, LineArgument.Create <Intf, A0, A1, A2>(a0, a1, a2), out result_) && result_ is Intf result__) { return(result__); } throw new LineException(previous, $"Appender doesn't have capability to append {nameof(Intf)}."); }