waoywssy / linfu

Automatically exported from code.google.com/p/linfu
0 stars 0 forks source link

Properties on proxied interfaces not found by reflection #42

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If I proxy an interface with properties, the properties are not found by 
reflection. If instead I proxy an abstract class with abstract properties 
everything is fine.

I attached a patch file, containing two tests that reproduce the problem.

Regards
Stefan Lieser
--
http://lieser-online.de
http://clean-code-developer.de

Original issue reported on code.google.com by stefan.l...@googlemail.com on 22 Mar 2010 at 5:05

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Stefan,

Although I couldn't find a way to directly make the interface properties 
visible in
the test, here is a simple workaround that you can use if you're working with
interface properties:

var proxyFactory = new ProxyFactory();
            var wrapper = new InvokeWrapper();
            var customer = proxyFactory.CreateProxy<ICustomer>(wrapper,
typeof(INotifyPropertyChanged));

            BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
            Type proxyType = customer.GetType();

var typeProperties = proxyType.GetProperties();

var allProperties = (from currentInterface in proxyType.GetInterfaces()
                          from property in currentInterface.GetProperties()
                          select property).ToList();

allProperties.AddRange(typeProperties);

// Do something with the interface properties here...

Original comment by Philip.L...@gmail.com on 22 Mar 2010 at 9:23

GoogleCodeExporter commented 9 years ago
Hi Philip,

thanks for the suggested workaround!

The problem is, I'm not the one who consumes the proxies. It is WPF when I 
databind the objects ;-) WPF does not 
look into all interfaces, obviously.

I have found another sort of workaround: with Castle DynamicProxy it works. I 
don't know how they implement it of 
course.

Regards
Stefan Lieser

Original comment by stefan.l...@googlemail.com on 24 Mar 2010 at 8:13