コード例 #1
0
        /// <summary>
        /// Append <see cref="StringLocalizerParameter"/>.
        /// </summary>
        /// <param name="appender"></param>
        /// <param name="previous"></param>
        /// <param name="parameterName"></param>
        /// <param name="parameterValue"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public virtual bool TryCreate(ILineFactory appender, ILine previous, string parameterName, string parameterValue, out ILineParameter result)
        {
            // Try resolve
            ILineArgument args;
            ILine         resolved;

            if (Resolver.TryResolveParameter(previous, parameterName, parameterValue, out args) && this.TryCreate(previous, args, out resolved) && resolved is ILineParameter castedResolved)
            {
                // Return as parameter and as resolved instance
                result = castedResolved;
                return(true);
            }

            IParameterInfo pi;

            if (ParameterInfos.TryGetValue(parameterName, out pi))
            {
                if (pi.InterfaceType == typeof(ILineHint))
                {
                    result = new StringLocalizerHint(appender, previous, parameterName, parameterValue); return(true);
                }
                if (pi.InterfaceType == typeof(ILineCanonicalKey))
                {
                    result = new StringLocalizerCanonicalKey(appender, previous, parameterName, parameterValue); return(true);
                }
                if (pi.InterfaceType == typeof(ILineNonCanonicalKey))
                {
                    result = new StringLocalizerNonCanonicalKey(appender, previous, parameterName, parameterValue); return(true);
                }
            }

            // Return as parameter
            result = new StringLocalizerParameter(appender, previous, parameterName, parameterValue);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Append key.
        /// </summary>
        /// <param name="appender"></param>
        /// <param name="previous"></param>
        /// <param name="parameterName"></param>
        /// <param name="parameterValue"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public virtual bool TryCreate(ILineFactory appender, ILine previous, string parameterName, string parameterValue, out ILineNonCanonicalKey result)
        {
            // Try resolve
            ILineArgument args;
            ILine         resolved;

            if (Resolver.TryResolveParameter(previous, parameterName, parameterValue, out args) && this.TryCreate(previous, args, out resolved) && resolved is ILineNonCanonicalKey castedResolved)
            {
                // Return as parameter and as resolved instance
                result = castedResolved;
                return(true);
            }

            result = new StringLocalizerNonCanonicalKey(appender, previous, parameterName, parameterValue);
            return(true);
        }