Finnaly我用附加的类型选择器(通过字符串)实现了它。
const string PropertyTypeStartWithSelector = "Diabdis.";
static IEnumerable<PropertyWithAttribute> GetAuthorizeIdentifierAttribute(Type type, string propertyPathPrefix)
{
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
//check current property
var result = properties
.Where(prop => Attribute.IsDefined(prop, typeof(AggregateAuthorizeIdentifierAttribute)))
.Select(p => new PropertyWithAttribute()
{
PropertyPath = propertyPathPrefix == null ? p.Name : $"{propertyPathPrefix}{PropertyPathSeparator}{p.Name}",
Attribute = p.GetCustomAttribute<AggregateAuthorizeIdentifierAttribute>(true)
})
.ToList();
//check deeper properties, BUT just selector classes
result.AddRange(properties
.Where(p => p.DeclaringType.FullName.StartsWith(PropertyTypeStartWithSelector))
.SelectMany(p => GetAuthorizeIdentifierAttribute(p.PropertyType, propertyPathPrefix == null ? p.Name : $"{propertyPathPrefix}{PropertyPathSeparator}{p.Name}")));
return result;
}