What are the challenges you face when working across database platforms? Take the survey
Options

10.3 crashes when reflecting embedded methods

Trying to reflect the Main method crashes Reflector 10.3 without comment

internal static class NinetyNineBottlesOfBeer
{
    private static void Main()
    {
        foreach (var line in GetSongText())
            System.Console.WriteLine(line);

        System.Console.ReadLine();

        System.Collections.Generic.IEnumerable<string> GetSongText()
        {
            var numberOfBottles = 99;

            do
            {
                var oldNumberText = GetNumberText(numberOfBottles);

                if (numberOfBottles > 1)
                {
                    yield return $"{oldNumberText} bottles of beer on the wall,";
                    yield return $"{oldNumberText} bottles of beer.";
                    yield return "Take one down, pass it around,";

                    numberOfBottles--;

                    var newNumberText = GetNumberText(numberOfBottles);

                    if (numberOfBottles > 1)
                        yield return $"{newNumberText} bottles of beer on the wall.";
                    else
                        yield return $"{newNumberText} last bottle of beer on the wall.";
                }
                else
                {
                    yield return $"{oldNumberText} last bottle of beer on the wall,";
                    yield return $"{oldNumberText} last bottle of beer.";
                    yield return "Take it down, pass it around,";
                    yield return "No more bottles of beer on the wall.";

                    numberOfBottles--;
                }

                yield return string.Empty;
            } while (numberOfBottles > 0);

            string GetNumberText(int number)
            {
                switch (number / 10)
                {
                    case 9:
                        return GetComboNumberText("Ninety", GetLastDigitText(number - 90));
                    case 8:
                        return GetComboNumberText("Eighty", GetLastDigitText(number - 80));
                    case 7:
                        return GetComboNumberText("Seventy", GetLastDigitText(number - 70));
                    case 6:
                        return GetComboNumberText("Sixty", GetLastDigitText(number - 60));
                    case 5:
                        return GetComboNumberText("Fifty", GetLastDigitText(number - 50));
                    case 4:
                        return GetComboNumberText("Fourty", GetLastDigitText(number - 40));
                    case 3:
                        return GetComboNumberText("Thirty", GetLastDigitText(number - 30));
                    case 2:
                        return GetComboNumberText("Twenty", GetLastDigitText(number - 20));
                    case 1:
                        return GetTeenNumberText(number);
                    case 0:
                        return GetLastDigitText(number);
                    default:
                        throw new System.NotSupportedException();
                }

                string GetComboNumberText(string tens, string ones) => ones != null ? $"{tens}-{ones}" : tens;

                string GetTeenNumberText(int teenNumber)
                {
                    switch (teenNumber)
                    {
                        case 19:
                            return "Nineteen";
                        case 18:
                            return "Eighteen";
                        case 17:
                            return "Seventeen";
                        case 16:
                            return "Sixteen";
                        case 15:
                            return "Fifteen";
                        case 14:
                            return "Fourteen";
                        case 13:
                            return "Thirteen";
                        case 12:
                            return "Twelve";
                        case 11:
                            return "Eleven";
                        case 10:
                            return "Ten";
                        default:
                            throw new System.NotSupportedException();
                    }
                }

                string GetLastDigitText(int lastDigit)
                {
                    switch (lastDigit)
                    {
                        case 9:
                            return "Nine";
                        case 8:
                            return "Eight";
                        case 7:
                            return "Seven";
                        case 6:
                            return "Six";
                        case 5:
                            return "Five";
                        case 4:
                            return "Four";
                        case 3:
                            return "Three";
                        case 2:
                            return "Two";
                        case 1:
                            return "One";
                        case 0:
                            return null;
                        default:
                            throw new System.NotSupportedException();
                    }
                }
            }
        }
    }
}

Tagged:

Answers

  • Options
    Hi, 

    Thank you for your post!

    This error has been reproduced and a bug logged for it. At the moment we are unable to provide an ETA on the fix. Until then, I recommend switching the optimization level to C# 6 as a workaround:


    Kind regards

    Robyn Edwards | Redgate Software
    Have you visited our Help Center?
Sign In or Register to comment.