castleproject / Core

Castle Core, including Castle DynamicProxy, Logging Services and DictionaryAdapter
http://www.castleproject.org/
Other
2.19k stars 466 forks source link

[FEATURE] Allow replication of attributes on mixins or attributes on inherited interfaces #607

Closed ExusAltimus closed 1 year ago

ExusAltimus commented 2 years ago

I have a scenario where the attribute I want on the proxy's property is not being replicated over from a mixin. The attribute itself is sealed and I can't modify the AttributeUsage to set Inherited to false.

The feature itself was considered once before in https://github.com/castleproject/Core/blob/d88e94447150996973d947a150ffda5efc0c3c1c/src/Castle.Core/DynamicProxy/Internal/AttributeUtil.cs#L119 Quoting the comment

// Later, there might be more special cases requiring attribute replication,
// which might justify creating a `SpecialCaseAttributeThatShouldBeReplicated`
// method and an `AttributesToAlwaysReplicate` class. For the moment, `Param-
// ArrayAttribute` is the only special case, so keep it simple for now:

Also it would be nice if we could also apply Attributes to proxy members and not only the class using ProxyGenerationOptions :>)

stakx commented 2 years ago

I have a scenario where the attribute I want on the proxy's property is not being replicated over from a mixin.

Sounds like a reasonable request, even though it may be an edge case.

Also it would be nice if we could also apply Attributes to proxy members and not only the class

In my opinion, that doesn't fit DynamicProxy's purpose very well. DynamicProxy's main goal is to provide you with a (programmable) instance of some type, not to derive arbitrarily modified types at runtime. Changing a type at the method level isn't something you can currently do with DynamicProxy (IIRC).

That said, I'll grant you that DynamicProxy's public API for handling custom attributes is pretty coarse-grained.