neuecc/MarkdownGenerator

InvalidCastException is thrown when an underlying type of Enum cannot be casted to Int32.

AdomasBekeras opened this issue · 1 comments

InvalidCastException is thrown when an underlying type of Enum cannot be casted to Int32.

Stack trace:

   at MarkdownWikiGenerator.MarkdownableType.<ToString>b__18_27(String x) in ...\MarkdownGenerator\MarkdownGenerator.cs:line 186
   at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()
   at System.Linq.Buffer1..ctor(IEnumerable1 source)
   at System.Linq.OrderedEnumerable1.<GetEnumerator>d__1.MoveNext()
   at System.Linq.Buffer1..ctor(IEnumerable1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
   at MarkdownWikiGenerator.MarkdownableType.ToString() in ...\MarkdownGenerator.cs:line 185
   at MarkdownWikiGenerator.Program.Main(String[] args) in ...\MarkdownGenerator\Program.cs:line 55

How to reproduce the issue:

Create this enum and try to use the MarkdownGenerator on it.

namespace Test
{
    public enum test : short
    {
        test =0,
        test2
    }
}

This can be fixed by checking the exact underlying type of the Enum and converting to it instead of always casting to Int32 with:
(Convert.ChangeType(Enum.Parse(type, x), Enum.GetUnderlyingType(type)))

Should be fixed in #11