[
  {
    "name": "author-speak-before",
    "value": "In this lesson, we will create an extension method in C# which gets a human-readable description from an Enum value."
  },
  {
    "name": "author-speak-before",
    "value": "We will start by creating a new static class called `EnumExtensions`."
  },
  {
    "name": "editor-type",
    "value": "public static class EnumExtensions\n{\n\n}"
  },
  {
    "name": "arrow-up",
    "value": "1"
  },
  {
    "name": "author-speak-before",
    "value": "Now let's define the signature of the method."
  },
  {
    "name": "editor-type",
    "value": "    public static string GetDescriptionFromAttribute(this Enum value)\n    {\n\n    }"
  },
  {
    "name": "author-speak-before",
    "value": "This is an extension method because the 'this' keyword with `Enum` is used in the parameter. This means our method extends the Enum type."
  },
  {
    "name": "author-speak-before",
    "value": "Now, let's get the field info of the Enum member."
  },
  {
    "name": "arrow-up",
    "value": "1"
  },
  {
    "name": "editor-type",
    "value": "        var fieldInfo = value.GetType().GetField(value.ToString());"
  },
  {
    "name": "enter",
    "value": "1"
  },
  {
    "name": "author-speak-before",
    "value": "We use reflection to get the FieldInfo of this enum type. Now let's process the edge-case where the value is null."
  },
  {
    "name": "editor-type",
    "value": "        if (fieldInfo == null) return value.ToString();"
  },
  {
    "name": "enter",
    "value": "1"
  },
  {
    "name": "author-speak-before",
    "value": "If the FieldInfo is null, we return the original string representation of the enum value."
  },
  {
    "name": "author-speak-before",
    "value": "Up next, we acquire the custom attributes associated with our Enum value."
  },
  {
    "name": "editor-type",
    "value": "        var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);"
  },
  {
    "name": "enter",
    "value": "1"
  },
  {
    "name": "author-speak-before",
    "value": "Now, we check to see if there is at least one DescriptionAttribute. If there is, we return the description from the first attribute, otherwise we will return the original value."
  },
  {
    "name": "editor-type",
    "value": "        return attributes.Any() ? attributes[0].Description : value.ToString();"
  },
  {
    "name": "author-speak-before",
    "value": "Since we're using System, the component model, and LINQ, we need to add a using statement for each of them."
  },
  {
    "name": "arrow-up",
    "value": "7"
  },
  {
    "name": "arrow-left",
    "value": "40"
  },
  {
    "name": "editor-type",
    "value": "using System;\nusing System.ComponentModel;\nusing System.Linq;\n\n"
  },
  {
    "name": "author-speak-before",
    "value": "And that's it! We've created an extension method that will retrieve a description from an Enum's attributes."
  }
]
