32 lines
966 B
C#
32 lines
966 B
C#
using System.ComponentModel;
|
|
using System.Windows.Markup;
|
|
|
|
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
|
using ShrlAlgoToolkit;
|
|
using ShrlAlgoToolkit.RevitAddins;
|
|
using ShrlAlgoToolkit.RevitAddins.UI;
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters
|
|
{
|
|
public class EnumDescriptionExtension : MarkupExtension
|
|
{
|
|
private readonly object _enumValue;
|
|
|
|
public EnumDescriptionExtension(object enumValue)
|
|
{
|
|
_enumValue = enumValue;
|
|
}
|
|
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
if (_enumValue == null) return string.Empty;
|
|
|
|
var field = _enumValue.GetType().GetField(_enumValue.ToString());
|
|
var attribute = field?.GetCustomAttributes(typeof(DescriptionAttribute), false)
|
|
.FirstOrDefault() as DescriptionAttribute;
|
|
|
|
return attribute?.Description ?? _enumValue.ToString();
|
|
}
|
|
}
|
|
}
|