コード例 #1
0
        /// <summary>
        /// Append <see cref="LineParameter"/>.
        /// </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 LineHint(appender, previous, parameterName, parameterValue); return(true);
                }
                if (pi.InterfaceType == typeof(ILineCanonicalKey))
                {
                    result = new LineCanonicalKey(appender, previous, parameterName, parameterValue); return(true);
                }
                if (pi.InterfaceType == typeof(ILineNonCanonicalKey))
                {
                    result = new LineNonCanonicalKey(appender, previous, parameterName, parameterValue); return(true);
                }
            }

            // Return as parameter
            result = new LineParameter(appender, previous, parameterName, parameterValue);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Convert <paramref name="match"/> to line where occurance indices are correct.
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        public static ILine ToLine(this ILinePatternMatch match)
        {
            // Apply parameter qualifiers
            ILine line = null;

            for (int i = 0; i < match.PartValues.Length; i++)
            {
                string parameterValue = match.PartValues[i];
                if (parameterValue == null)
                {
                    continue;
                }
                string parameterName = match.Pattern.CaptureParts[i].ParameterName;
                line = new LineParameter(null, line, parameterName, parameterValue);

                // TODO Put line parts in occurance order //
            }
            return(line);
        }