コード例 #1
0
ファイル: QuantityType.cs プロジェクト: Majunga/Food
        public static string GetFriendlyString(this QuantityType quantityType)
        {
            var fieldInfo = quantityType.GetType().GetField(quantityType.ToString());

            var descriptionAttributes = fieldInfo.GetCustomAttributes(
                typeof(DisplayAttribute), false) as DisplayAttribute[];

            if ((descriptionAttributes ?? throw new InvalidOperationException()).Any() && descriptionAttributes[0].ResourceType != null)
            {
                return(lookupResource(descriptionAttributes[0].ResourceType, descriptionAttributes[0].Name));
            }

            return((descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : quantityType.ToString());
        }