GetCustomAttribute retourne null

Quelqu'un peut-il m'expliquer pourquoi Value.GetType().GetCustomAttribute retourne null? J'ai regardé une dizaine de tutoriels sur la façon d'obtenir les attributs d'un type énuméré membre. N'importe qui GetCustomAttribute* méthode que j'utilise, je n'ai pas d'attributs personnalisés retourné.

using System;
using System.ComponentModel;
using System.Reflection;

public enum Foo
{
    [Bar(Name = "Bar")]
    Baz,
}

[AttributeUsage(AttributeTargets.Field)]
public class BarAttribute : Attribute
{
    public string Name;
}

public static class FooExtensions
{
    public static string Name(this Foo Value)
    {
        return Value.GetType().GetCustomAttribute<BarAttribute>(true).Name;
    }
}
  • Peut-être que je devrais reformuler ma question. Je comprends pourquoi NullReferenceException est levée. Ce que je ne comprends pas, c'est pourquoi Value.GetType().GetCustomAttribute retourne null.