Esempio n. 1
0
        /// <summary>
        /// Returns a built pattern. This is mostly to keep the API for the builder separate from that of the pattern,
        /// and for thread safety (publishing a new object, thus leading to a memory barrier).
        /// Note that this builder *must not* be used after the result has been built.
        /// </summary>
        internal IPartialPattern <TResult> Build(TResult sample)
        {
            Action <TResult, StringBuilder> formatDelegate = null;

            foreach (Action <TResult, StringBuilder> formatAction in formatActions)
            {
                IPostPatternParseFormatAction postAction = formatAction.Target as IPostPatternParseFormatAction;
                formatDelegate += postAction == null ? formatAction : postAction.BuildFormatAction(usedFields);
            }
            return(new SteppedPattern(formatDelegate, formatOnly ? null : parseActions.ToArray(), bucketProvider, usedFields, sample));
        }
        /// <summary>
        /// Returns a built pattern. This is mostly to keep the API for the builder separate from that of the pattern,
        /// and for thread safety (publishing a new object, thus leading to a memory barrier).
        /// Note that this builder *must not* be used after the result has been built.
        /// </summary>
        internal IPartialPattern <TResult> Build(TResult sample)
        {
            // If we've got an embedded date and any *other* date fields, throw.
            if (usedFields.HasAny(PatternFields.EmbeddedDate) &&
                usedFields.HasAny(PatternFields.AllDateFields & ~PatternFields.EmbeddedDate))
            {
                throw new InvalidPatternException(TextErrorMessages.DateFieldAndEmbeddedDate);
            }
            // Ditto for time
            if (usedFields.HasAny(PatternFields.EmbeddedTime) &&
                usedFields.HasAny(PatternFields.AllTimeFields & ~PatternFields.EmbeddedTime))
            {
                throw new InvalidPatternException(TextErrorMessages.TimeFieldAndEmbeddedTime);
            }

            Action <TResult, StringBuilder> formatDelegate = null;

            foreach (Action <TResult, StringBuilder> formatAction in formatActions)
            {
                IPostPatternParseFormatAction postAction = formatAction.Target as IPostPatternParseFormatAction;
                formatDelegate += postAction == null ? formatAction : postAction.BuildFormatAction(usedFields);
            }
            return(new SteppedPattern(formatDelegate, formatOnly ? null : parseActions.ToArray(), bucketProvider, usedFields, sample));
        }