public static T GetDefaultValue <T>(this SitenameComponent enumValue) { var type = typeof(SitenameComponent); var member = type.GetMember(enumValue.ToString()); if (member[0].GetCustomAttribute(typeof(DefaultValueAttribute)) is DefaultValueAttribute attribute) { return((T)attribute.Value); } return(default(T)); }
/// <summary> /// Evaluates the Sitename and returns the specified component /// </summary> /// <param name="component">the component that shall be returned</param> /// <param name="sitename">the sitename that is to be evaluated. If not specified the method will read the EnvironmentVariable "WEBSITE_SITE_NAME" which will be set when running on azure.</param> /// <returns>the specified component of the sitename </returns> public static string EvaluateSitename(SitenameComponent component, string sitename = null) { var result = component.GetDefaultValue <string>(); sitename = sitename ?? SettingsReader.ApplicationSettings.WebSiteName; Match m = SiteNamePattern.Match(sitename); if (m.Success) { result = m.Groups[component.ToString()].Value; } return(result); }