我正在做一个项目,我们在 AssemblyInfo.cs 中有几个属性,这些属性被多播到特定类的方法。
[assembly: Repeatable(
AspectPriority = 2,
AttributeTargetAssemblies = "MyNamespace",
AttributeTargetTypes = "MyNamespace.MyClass",
AttributeTargetMemberAttributes = MulticastAttributes.Public,
AttributeTargetMembers = "*Impl", Prefix = "Cls")]
我不喜欢这一点,它在 AssemblyInfo 中加入了一段逻辑(Info,请注意!),对于初学者来说,它根本不应该包含任何逻辑。最糟糕的是,实际的 MyClass.cs 在文件中的任何位置都没有该属性,并且完全不清楚此类的方法是否具有它们。从我的角度来看,它极大地损害了代码的可读性(更不用说过度使用 PostSharp 会使调试成为一场噩梦)。尤其是当您有多个多播属性时。
这里的最佳做法是什么?有没有人在使用这样的 PostSharp 属性?