private static void HandleHalfAmPmDesignator <TResult, TBucket> (int count, string specifiedDesignator, int specifiedDesignatorValue, Func <TResult, int> hourOfDayGetter, Action <TBucket, int> amPmSetter, SteppedPatternBuilder <TResult, TBucket> builder) where TBucket : ParseBucket <TResult> { CompareInfo compareInfo = builder.FormatInfo.CompareInfo; if (count == 1) { string abbreviation = specifiedDesignator.Substring(0, 1); builder.AddParseAction((str, bucket) => { int value = str.MatchCaseInsensitive(abbreviation, compareInfo, true) ? specifiedDesignatorValue : 1 - specifiedDesignatorValue; amPmSetter(bucket, value); return(null); }); builder.AddFormatAction((value, sb) => { // Only append anything if it's the non-empty designator. if (hourOfDayGetter(value) / 12 == specifiedDesignatorValue) { sb.Append(specifiedDesignator[0]); } }); return; } builder.AddParseAction((str, bucket) => { int value = str.MatchCaseInsensitive(specifiedDesignator, compareInfo, true) ? specifiedDesignatorValue : 1 - specifiedDesignatorValue; amPmSetter(bucket, value); return(null); }); builder.AddFormatAction((value, sb) => { // Only append anything if it's the non-empty designator. if (hourOfDayGetter(value) / 12 == specifiedDesignatorValue) { sb.Append(specifiedDesignator); } }); }