/// <summary> /// Extension method that will lookup the value of an enumeration by the enumeration type name. /// </summary> /// <param name="source">The target <see cref="IDotNetEnum"/> model to get the enumeration value from.</param> /// <param name="enumName">The target numerical named item to use to lookup the enumeration value.</param> /// <returns>The target enumeration value or null if it could not be found.</returns> public static string FormatCSharpEnumValueSyntax(this IDotNetEnum source, string enumName) { if (source == null) { return(null); } if (string.IsNullOrEmpty(enumName)) { return(null); } if (!source.Values.Any()) { return(null); } var enumValue = source.Values.Where(v => string.Equals(v.Name, enumName)).Select(v => v.Value).FirstOrDefault(); return(enumValue); }
/// <summary> /// Extension method that will lookup the enumeration type based on the provided value. /// </summary> /// <param name="source">The target <see cref="IDotNetEnum"/> model to get the enumeration type from.</param> /// <param name="value">The target numerical value to use to lookup the enumeration type.</param> /// <returns>The fully qualified enumeration type or null if the enumeration type could not be found.</returns> public static string FormatCSharpEnumTypeSyntax(this IDotNetEnum source, string value) { if (source == null) { return(null); } if (string.IsNullOrEmpty(value)) { return(null); } if (!source.Values.Any()) { return(null); } var enumValue = source.Values.Where(v => string.Equals(v.Value, value)).Select(v => v.Name).FirstOrDefault(); return(enumValue != null ? $"{source.Namespace}.{source.Name}.{enumValue}" : null); }