waoywssy / linfu

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

Nested classes no longer supported in DP2 #35

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a dynamic proxy of a class which is nested
2. Confirm that works in Linfu.DynamicProxy
3. Confirm that fails in Linfu.Proxy (DP2)

What is the expected output? What do you see instead?
-A proxied type is generated and an instance is returned

What version of the product are you using? On what operating system?
-LinFu.Core, Version 2.2.0.19938

Please provide any additional information below.
-Exception info is as follows:
System.ArgumentException: The proxy factory can only generate proxies from 
public base classes.
 Parameter name: baseType.

 seems to happen in the ProxyFactory.CreateProxyType(Type baseType, 
IEnumerable<Type> baseInterfaces) method where it checks if the 
type.IsPublic. Nested types do not show as IsPublic. Could change to 
 !baseType.IsPublic && !baseType.IsNestedPublic

Original issue reported on code.google.com by petetran...@petegoo.com on 14 Sep 2009 at 11:15

GoogleCodeExporter commented 9 years ago
I managed to reproduce the bug but it'll take a while for me to do in 
Mono.Cecil what
DP1 does with System.Reflection.Emit. The problem seems to be that the Proxy 
Factory
class needs to generate a proxy type that matches the type attribute flags of 
the
nested base class that it's inheriting.

Here are the proxy type attributes being used in DP1:

TypeAttributes typeAttributes = TypeAttributes.AutoClass | TypeAttributes.Class 
|
                                            TypeAttributes.Public |
TypeAttributes.BeforeFieldInit;

Here are the proxy type attributes being used in DP2:

var attributes = TypeAttributes.AutoClass | TypeAttributes.Class |
TypeAttributes.BeforeFieldInit | TypeAttributes.Public;

Strangely enough, the DP1 version (the one that uses System.Reflection.Emit) 
works
fine, while the version that uses Cecil cannot properly create nested proxy 
types.
I'll have to check with Jb Evain and see what he says about it.

Original comment by Philip.L...@gmail.com on 15 Sep 2009 at 5:05