예제 #1
0
        /// <summary>
        /// Create line (part) with <paramref name="arguments"/>.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="previous"></param>
        /// <param name="arguments"></param>
        /// <returns>appended part</returns>
        /// <exception cref="LineException">If append failed due to unexpected reason</exception>
        public static ILine Create(this ILineFactory factory, ILine previous, ILineArgument arguments)
        {
            ILine result = null;

            if (factory.TryCreate(previous, arguments, out result))
            {
                return(result);
            }
            ILineFactoryByArgument argumentAdapter;

            if (LineFactoryByArgumentAdapter.Default.TryGet(arguments.GetType(), out argumentAdapter) && argumentAdapter.TryCreate(factory, previous, arguments, out result))
            {
                return(result);
            }
            throw new LineException(arguments, "Could not be appended");
        }
예제 #2
0
        /// <summary>
        /// Create line (part) with <paramref name="arguments"/>.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="previous"></param>
        /// <param name="arguments"></param>
        /// <param name="line"></param>
        /// <returns>try if create succeeded</returns>
        /// <exception cref="LineException">If append failed due to unexpected reason</exception>
        public static bool TryCreate(this ILineFactory factory, ILine previous, ILineArgument arguments, out ILine line)
        {
            if (factory == null)
            {
                line = previous; return(false);
            }
            if (factory is ILineFactoryByArgument argFactory && argFactory.TryCreate(factory, previous, arguments, out line))
            {
                return(true);
            }
            ILineFactoryByArgument argumentAdapter;

            if (LineFactoryByArgumentAdapter.Default.TryGet(arguments.GetType(), out argumentAdapter) && argumentAdapter.TryCreate(factory, previous, arguments, out line))
            {
                return(true);
            }
            line = default;
            return(false);
        }