/// <summary> /// 给非基元属性(不包括 string 类型)加上 Browserable = false /// </summary> /// <typeparam name="TEntity"></typeparam> public static void SetNotBrowserableForComplexProperty <TEntity>() { var pts = TypeDescriptor.GetProperties(typeof(TEntity));//.Cast<PropertyDescriptor>(); var builder = new RuntimeAttributeBuilder <TEntity>(); foreach (var pt in pts) { var opt = (PropertyDescriptor)pt; if (!(opt.PropertyType.IsPrimitive || opt.PropertyType == typeof(string)) && opt.IsBrowsable) { builder.Add(opt.Name, new BrowsableAttribute(false)); } } TypeDescriptorHelper.AddRuntimeAttribute <TEntity>(builder); }
public static void AddRuntimeAttribute <T>(RuntimeAttributeBuilder <T> builder) { TypeDescriptor.AddProvider(new RuntimeAttributeTypeDescriptorProvider(typeof(T), builder.PropAttrsMap), typeof(T)); }