Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up instance contributors into 3 single-purpose contributors #553

Merged
merged 3 commits into from
Jan 5, 2021

Conversation

stakx
Copy link
Member

@stakx stakx commented Jan 5, 2021

ProxyInstanceContributor and its subtypes currently have three responsibilities:

  1. adding an implementation for ISerializable
  2. adding an implementation for IProxyTargetAccessor
  3. reproducing the proxied type's non-inheritable custom attributes on the proxy type

This PR takes that type apart into three single-purpose contributors SerializableContributor, ProxyTargetAccessorContributor, and NonInheritableAttributesContributor, where each one is responsible for the aspect it is named after.

from `ProxyInstanceContributor`, and change proxy type generators to use
the new contributor for `IProxyTargetAccessor`. Remove everything that
has become redundant.
@stakx stakx force-pushed the dp/refactor/instance-contributors branch from 6e03540 to dbc13a6 Compare January 5, 2021 17:28
from `ProxyInstanceContributor`. Because it does not contribute a type,
it is not added to `GetTypeImplementerMapping`'s list of contributors,
but invoked directly in `GenerateType`.
as its sole remaining function is to implement `ISerializable`.
@stakx stakx force-pushed the dp/refactor/instance-contributors branch from dbc13a6 to 12f6964 Compare January 5, 2021 17:35
Copy link
Member Author

@stakx stakx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one thing for future consideration.

Comment on lines +53 to +64
// we can only change the target of the interface proxy
if (targetReference is FieldReference targetField)
{
dynProxySetTarget.CodeBuilder.AddStatement(
new AssignStatement(targetField,
new ConvertExpression(targetField.Fieldbuilder.FieldType, dynProxySetTarget.Arguments[0].ToExpression())));
}
else
{
dynProxySetTarget.CodeBuilder.AddStatement(
new ThrowStatement(typeof(InvalidOperationException), "Cannot change the target of the class proxy."));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the code comment and the exception message are somewhat misleading, since there are interface proxies that also don't support changing the target. While even interface proxies without a target have a __target field, setting it has no effect whatsoever.

This is the original implementation from ProxyInstanceContributor and I opted not to change it for now, but perhaps in the future, we want to formally disallow changing the target of interface proxies without a target...?

@stakx stakx merged commit 9143de2 into castleproject:master Jan 5, 2021
@stakx stakx deleted the dp/refactor/instance-contributors branch January 5, 2021 17:45
Copy link
Member

@jonorossi jonorossi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants