public static decimal ComputePaymentPerPeriod( decimal principalAmount, decimal ratePerPeriod, int termInPeriods) { s_lastCalculationTime = DateTime.Now; if (termInPeriods <= 0 || termInPeriods > MaxTermInMonths) { throw new ArgumentOutOfRangeException("termInPeriods"); } if (principalAmount < MinPrincipalAmount || principalAmount >= MaxPrincipalAmount) { // Violates the FxCop rule a: b throw new InvalidOperationException(string.Format( "Principal {0} is not valid", principalAmount.ToString("C", new CultureInfo("EN-us")))); } TooManyVariables(); try { // Violates the FxCop rule CA1804: RemoveUnusedLocals // http://msdn.microsoft.com/en-us/library/ms182278.aspx var unusedLocal = new IncorrectlyImplementsIDisposable(); var exponentBase = Convert.ToDouble(decimal.One + ratePerPeriod); var exponent = Convert.ToDecimal(Math.Pow(exponentBase, -1 * termInPeriods)); var payment = (ratePerPeriod * principalAmount) / (1m - exponent); payment = Math.Round(payment, 2, MidpointRounding.AwayFromZero); // Violates the StyleCop rule SA1507: CodeMustNotContainMultipleBlankLinesInARow // More information in the StyleCop help file: StyleCop.chm return(payment); } catch (ArithmeticException arithmeticException) { // Violates the FxCop rule CA2200: RethrowToPreserveStackDetails // http://msdn.microsoft.com/en-us/library/ms182363(v=VS.100).aspx throw arithmeticException; } }
public static decimal ComputePaymentPerPeriod( decimal principalAmount, decimal ratePerPeriod, int termInPeriods) { s_lastCalculationTime = DateTime.Now; if (termInPeriods <= 0 || termInPeriods > MaxTermInMonths) { throw new ArgumentOutOfRangeException("termInPeriods"); } if (principalAmount < MinPrincipalAmount || principalAmount >= MaxPrincipalAmount) { // Violates the FxCop rule a: b throw new InvalidOperationException(string.Format( "Principal {0} is not valid", principalAmount.ToString("C", new CultureInfo("EN-us")))); } TooManyVariables(); try { // Violates the FxCop rule CA1804: RemoveUnusedLocals // http://msdn.microsoft.com/en-us/library/ms182278.aspx var unusedLocal = new IncorrectlyImplementsIDisposable(); var exponentBase = Convert.ToDouble(decimal.One + ratePerPeriod); var exponent = Convert.ToDecimal(Math.Pow(exponentBase, -1 * termInPeriods)); var payment = (ratePerPeriod * principalAmount) / (1m - exponent); payment = Math.Round(payment, 2, MidpointRounding.AwayFromZero); // Violates the StyleCop rule SA1507: CodeMustNotContainMultipleBlankLinesInARow // More information in the StyleCop help file: StyleCop.chm return payment; } catch (ArithmeticException arithmeticException) { // Violates the FxCop rule CA2200: RethrowToPreserveStackDetails // http://msdn.microsoft.com/en-us/library/ms182363(v=VS.100).aspx throw arithmeticException; } }