我在程序集级将接口介绍多播到给定名称空间中的所有EF实体上,但我希望从介绍中排除该名称空间中从DbContext派生的任何类。不确定如何在不按名称显式排除每个DbContext派生类的情况下执行此操作。:(
[assembly: MyApi.IntroduceAspect(AttributeTargetTypes = "MyApi.Models.*")]
[assembly: MyApi.IntroduceAspect(AttributeTargetTypes = "MyApi.Models.SomeContext", AttributeExclude = true)]
[assembly: MyApi.IntroduceAspect(AttributeTargetTypes = "MyApi.Models.SomeOtherContext", AttributeExclude = true)]发布于 2018-08-17 23:22:29
属性多播不允许过滤目标类型的基类。对于这种过滤,您可以在方面中实现CompileTimeValidate方法,如果目标类型派生自DbContext,则返回false。
public override bool CompileTimeValidate(Type targetType)
{
if (typeof(DbContext).IsAssignableFrom(targetType))
return false;
return true;
}文档链接:http://doc.postsharp.net/aspect-validation
https://stackoverflow.com/questions/51524742
复制相似问题