-
Notifications
You must be signed in to change notification settings - Fork 471
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
Split up instance contributors into 3 single-purpose contributors #553
Conversation
from `ProxyInstanceContributor`, and change proxy type generators to use the new contributor for `IProxyTargetAccessor`. Remove everything that has become redundant.
6e03540
to
dbc13a6
Compare
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`.
dbc13a6
to
12f6964
Compare
There was a problem hiding this 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.
// 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.")); | ||
} |
There was a problem hiding this comment.
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...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice.
ProxyInstanceContributor
and its subtypes currently have three responsibilities:ISerializable
IProxyTargetAccessor
This PR takes that type apart into three single-purpose contributors
SerializableContributor
,ProxyTargetAccessorContributor
, andNonInheritableAttributesContributor
, where each one is responsible for the aspect it is named after.