Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        internal static bool TryCloneValue(this ILine line, out ILine value)
        {
            ILine valuePart;

            if (line == null || !line.TryGetStringPart(out valuePart))
            {
                value = default; return(false);
            }

            // Clone value
            ILine valueClone = null;

            if (valuePart is ILineString lineValue)
            {
                value = new LineStringPart(null, null, lineValue.String); return(true);
            }
            if (valueClone == null && valuePart is ILineParameterEnumerable lineParameters)
            {
                foreach (ILineParameter lineParameter in lineParameters)
                {
                    if (lineParameter.ParameterName == "String" && lineParameter.ParameterValue != null)
                    {
                        value = new LineHint(null, null, "String", lineParameter.ParameterValue); return(true);
                    }
                }
            }
            if (valueClone == null && valuePart is ILineParameter parameter && parameter.ParameterName == "String" && parameter.ParameterValue != null)
            {
                value = new LineHint(null, null, "String", parameter.ParameterValue); return(true);
            }

            value = default;
            return(false);
        }
        /// <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);
        }
Esempio n. 3
0
        /// <summary>
        /// Append <see cref="LineHint"/>.
        /// </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 ILineHint result)
        {
            // Try resolve
            ILineArgument args;
            ILine         resolved;

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

            // Return as parameter
            result = new LineHint(appender, previous, parameterName, parameterValue);
            return(true);
        }