Generating Proxy objects given an abstraction of the type being proxied
Closed this issue · 2 comments
Hi Stef,
I have been using this library for a few months now and it has been an absolute game changer so big thank you.
Given I have the following types which are to be proxied
public class Abstraction {}
public class Implementation : Abstraction {}
and there exists a method elsewhere in the library
public IReadOnlyCollection<Abstraction> GetAbstractions() {}
And that I have implemented partial interfaces with the proxy attribute as below.
[Proxy(typeof(Abstraction))]
public partial interface IAbstraction {}
[Proxy(typeof(Implementation))]
public partial interface IImplementation : IAbstraction {}
Currently, the proxied version of the GetAbstractions
method would return a set of AbstractionProxy
objects even if the _Instance
property is of type Implementation. What would be the easiest way to convert a set of AbstractionProxy
into the lowest level available abstraction? Would this be best via some reflection or is there something in your library I have overlooked?
Thank you again for your amazing work
@JROBOTO
Internally I use Mapster to map a real object to a proxy object (and the other way around).
So maybe you can use that as a solution for your question?
So mapster wasn't entirely what I needed. The biggest issue being I haven't implemented every type as an interface to proxy because the library is too big to do all at once when I don't necessarily need every type. What I have ended up doing is writing a scraper which runs on application startup finding all types and creating a dictionary to their implementation. Then when a type needs converting, if the instance type has not been proxied, see if the base type has been proxied and so on. If we get all the way to the root without finding a proxy implementation then we throw an exception but the library I am proxying, 99% of the objects converge on a single base object anyway so that shouldn't happen