Skip to content

Commit efbe23c

Browse files
committed
Only synthesize <Clone>$ for record proxies w/o target
1 parent 2adb7ca commit efbe23c

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ protected BaseClassProxyGenerator(ModuleScope scope, Type targetType, Type[] int
4141

4242
protected abstract ProxyTargetAccessorContributor GetProxyTargetAccessorContributor();
4343

44+
protected abstract RecordCloningContributor? GetRecordCloningContributor(INamingScope namingScope);
45+
4446
protected sealed override Type GenerateType(string name, INamingScope namingScope)
4547
{
4648
IEnumerable<ITypeContributor> contributors;
@@ -192,7 +194,11 @@ private IEnumerable<Type> GetTypeImplementerMapping(out IEnumerable<ITypeContrib
192194
}
193195
#endif
194196

195-
contributorsList.Add(new RecordCloningContributor(targetType, namingScope));
197+
var recordCloningContributor = GetRecordCloningContributor(namingScope);
198+
if (recordCloningContributor != null)
199+
{
200+
contributorsList.Add(recordCloningContributor);
201+
}
196202

197203
var proxyTargetAccessorContributor = GetProxyTargetAccessorContributor();
198204
contributorsList.Add(proxyTargetAccessorContributor);

src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@ protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContribu
5454
getTarget: () => ThisExpression.Instance,
5555
targetType);
5656
}
57+
58+
protected override RecordCloningContributor GetRecordCloningContributor(INamingScope namingScope)
59+
{
60+
return new RecordCloningContributor(targetType, namingScope);
61+
}
5762
}
5863
}

src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContribu
6969
targetType);
7070
}
7171

72+
protected override RecordCloningContributor GetRecordCloningContributor(INamingScope namingScope)
73+
{
74+
return null;
75+
}
76+
7277
private void CreateTargetField(ClassEmitter emitter)
7378
{
7479
targetField = emitter.CreateField("__target", targetType);

0 commit comments

Comments
 (0)