Files
test_demo/MX-PD-盘古 - new/PanGu.DieBonderApp/MainShell/Common/PropDescExtension.cs

29 lines
895 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Markup;
namespace MainShell.Common
{
[MarkupExtensionReturnType(typeof(string))]
public class PropDescExtension : MarkupExtension
{
public Type ForType { get; set; }
public string Property { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (ForType == null || string.IsNullOrWhiteSpace(Property)) return Property;
var pd = TypeDescriptor.GetProperties(ForType)[Property];
if (pd == null) return Property;
var desc = pd.Attributes.OfType<DescriptionAttribute>().FirstOrDefault();
return string.IsNullOrWhiteSpace(desc?.Description) ? Property : desc.Description;
}
}
}