Example #1
0
        /// <summary>Gets a date schedule frequency.
        /// </summary>
        /// <param name="frequency">The frequency in its <see cref="System.String"/> representation; perhaps a <see cref="TenorTimeSpan"/> in its <see cref="System.String"/> representation.</param>
        /// <param name="value">The date schedule frequency (output).</param>
        /// <param name="addIntoPool">If <paramref name="frequency"/> represents a individual frequency,
        /// the corresponding <see cref="IDateScheduleFrequency"/> will be added to the <see cref="DateScheduleFrequency"/> if set to <c>true</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <remarks>If <paramref name="frequency"/> does not represents an item of the pool, try to create to convert <paramref name="frequency"/> to a  <see cref="TenorTimeSpan"/> object first.</remarks>
        public static bool TryGetValue(string frequency, out IDateScheduleFrequency value, bool addIntoPool = false)
        {
            if ((frequency == null) || (frequency.Length == 0))
            {
                value = null;
                return(false);
            }
            if (sm_Pool.TryGetValue(frequency, out value) == true)
            {
                return(true);
            }

            TenorTimeSpan tenorFrequency;   // try to generate a individual frequency:

            if (TenorTimeSpan.TryParse(frequency, out tenorFrequency) == false)
            {
                value = null;
                return(false);
            }
            if (IndividualDateScheduleFrequency.TryCreate(tenorFrequency, out value) == true)
            {
                if (addIntoPool)
                {
                    sm_Pool.Add(value);
                }
                return(true);
            }
            value = null;
            return(false);
        }
 /// <summary>Gets a <see cref="IndividualDateScheduleFrequency"/> object.
 /// </summary>
 /// <param name="frequencyTenor">The frequency tenor.</param>
 /// <param name="individualDateScheduleFrequency">The individual date schedule frequency (output).</param>
 /// <returns>A value indicating whether <paramref name="individualDateScheduleFrequency"/> contains valid data.</returns>
 internal static bool TryCreate(TenorTimeSpan frequencyTenor, out IDateScheduleFrequency individualDateScheduleFrequency)
 {
     if (TenorTimeSpan.IsNull(frequencyTenor) || (frequencyTenor.IsPositive == false))
     {
         individualDateScheduleFrequency = null;
         return(false);
     }
     individualDateScheduleFrequency = new IndividualDateScheduleFrequency(frequencyTenor);
     return(true);
 }