You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with MemberCloner, you must do at least 2 loops through all copied types - implicit one (in MemberCloner), and explicit one (when you add types to module).
For small assemblies it won't matter, but for larger - it could cause huge processing time.
Callbacks system can solve this - user can define their callback types, cache processed types (for example interfaces), do some minor processing, and add result automatically to module - in a single iteration.
Proposal
To MemberCloner constructor, add argument Action<IMemberDescriptor>, and invoke it directly after the member is fully cloned.
Alternatives
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Perhaps as an alternative to calbacks we could also consider implementing a listener pattern for easier customization and case distinction from the user's perspective. This is particularly useful for users that just want to add their included types to the target module, and thus only need a case for TypeDefinition. Something like the following:
publicclassMyListener:MemberClonerListener{publicoverridevoidOnClonedMember(IMetadataMemberoriginal,IMetadataMembercloned){// called for every member.}publicoverridevoidOnClonedType(TypeDefinitionoriginal,TypeDefinitioncloned){// called for every type only}publicoverridevoidOnClonedMethod(MethodDefinitionoriginal,MethodDefinitioncloned){// called for every method only.}// ...}varcloner=new MemberCloner(targetModule,new MyListener());
We can easily do both as well. The callback version is just a special case of a full listener version, as can be seen in a potential implementation below:
publicclassCallbackCloneListener:MemberClonerListener{privatereadonlyAction<IMetadataMember,IMetadataMember>_callback;publicCallbackCloneListener(Action<IMetadataMember,IMetadataMember>callback){_callback=callback;}publicoverridevoidOnClonedMember(IMetadataMemberoriginal,IMetadataMembercloned)=> _callback(original, cloned);}varcloner=new MemberCloner(targetModule,(original,cloned)=>{ ...});// this would be shorthand for;// var cloner = new MemberCloner(targetModule, new CallbackCloneListener((original, cloned) => { ... }));
Problem Description
When working with MemberCloner, you must do at least 2 loops through all copied types - implicit one (in MemberCloner), and explicit one (when you add types to module).
For small assemblies it won't matter, but for larger - it could cause huge processing time.
Callbacks system can solve this - user can define their callback types, cache processed types (for example interfaces), do some minor processing, and add result automatically to module - in a single iteration.
Proposal
To MemberCloner constructor, add argument
Action<IMemberDescriptor>
, and invoke it directly after the member is fully cloned.Alternatives
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: