Example #1
0
        /// <summary>
        /// Resolve <paramref name="identifier"/> to <typeparamref name="T"/>.
        /// </summary>
        /// <param name="identifier"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns><typeparamref name="T"/> or null</returns>
        /// <exception cref="ObjectDisposedException">resolver is disposed</exception>
        /// <exception cref="LocalizationException">If resolve fails.</exception>
        public T Resolve <T>(string identifier)
        {
            StructList4 <Exception> errors = new StructList4 <Exception>();

            List <IResolver> list = resolversByType.TryGetList(typeof(T));

            if (list != null)
            {
                foreach (IResolver resolver in list)
                {
                    try
                    {
                        return(((IResolver <T>)resolver).Resolve(identifier));
                    } catch (Exception e)
                    {
                        errors.Add(e);
                    }
                }
            }

            foreach (IGenericResolver genericResolver in genericResolvers)
            {
                try
                {
                    return(genericResolver.Resolve <T>(identifier));
                }
                catch (Exception e)
                {
                    errors.Add(e);
                }
            }

            string msg = $"Failed to resolve {identifier} to {typeof(T).FullName}.";

            if (errors.Count == 0)
            {
                throw new LocalizationException(msg);
            }
            throw new LocalizationException(msg, new AggregateException(errors));
        }
Example #2
0
        /// <summary>
        /// Try to resolve parameter into line arguments.
        /// </summary>
        /// <param name="previous">(optional) previous parts</param>
        /// <param name="parameterName"></param>
        /// <param name="parameterValue"></param>
        /// <param name="resolvedLineArgument"></param>
        /// <returns></returns>
        public bool TryResolveParameter(ILine previous, string parameterName, string parameterValue, out ILineArgument resolvedLineArgument)
        {
            List <IParameterResolver> list = resolversByParameterName.TryGetList(parameterName);

            if (list != null)
            {
                foreach (IParameterResolver resolver in list)
                {
                    if (resolver.TryResolveParameter(previous, parameterName, parameterValue, out resolvedLineArgument))
                    {
                        return(true);
                    }
                }
            }

            resolvedLineArgument = default;
            return(false);
        }