mercredi 30 novembre 2016

Unexpected difference in DefaultValue and RawDefaultValue for Enum parameters

Consider the following example:

class Program
{
    static void Main(string[] args)
    {
        foreach(var par in typeof(A).GetMethod("Method").GetParameters())
        {
            Console.WriteLine("Def {0}, RawDef {1}",
                par.DefaultValue, par.RawDefaultValue);
        }
    }
}

class A
{
    public void Method(int a = 5, B b = B.b){}
}
enum B
{
    a = 0, b = 1
}

According to the documentation of RawDefaultValue and DefaultValue, with support from StackOverflow, these two methods of accessing the default value should return the same data.

But instead, I get the following output:

Def 5, RawDef 5
Def b, RawDef 1

So, apparently, RawDefaultValue drops the information about the parameter being an enum type.

My question: is it a bug or is it justified by another part of the documentation?





Aucun commentaire:

Enregistrer un commentaire