This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
/
DYNPROXY-144.xml
87 lines (84 loc) · 6.79 KB
/
DYNPROXY-144.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?xml version="1.0" encoding="utf-8"?>
<issues>
<issue>
<field name="Priority">
<value>Normal</value>
</field>
<field name="Type">
<value>Bug</value>
</field>
<field name="State">
<value>Fixed</value>
</field>
<field name="Assignee" />
<field name="Subsystem">
<value>No subsystem</value>
</field>
<field name="Fix versions">
<value>2.5.2</value>
</field>
<field name="Affected versions">
<value>2.5</value>
</field>
<field name="Fixed in build" />
<field name="numberInProject">
<value>144</value>
</field>
<field name="summary">
<value>params argument not supported in constructor</value>
</field>
<field name="description">
<value>When using {{Castle.DynamicProxy.ProxyGenerator.CreateClassProxy }}
params attribute is lost in proxy class.
{code lang=java}
public class C
{
protected C(params object[] o) { }
}
{code}
is created as
{code lang=java}
public class CProxy
{
protected CProxy(object[] o) { }
}
{code}
This information can be obtained in
{{Castle.DynamicProxy.Generators.BaseProxyGenerator.GenerateConstructor }}
with
{code lang=java}
lastArgIsParams =
baseConstructorParams[baseConstructorParams.Length - 1]
.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0;
{code}
but I don't know how to propagate it to builder ;(</value>
</field>
<field name="created">
<value>1285938545729</value>
</field>
<field name="updated">
<value>1289699151458</value>
</field>
<field name="reporterName">
<value>rikard.pavelic</value>
</field>
<field name="updaterName">
<value>xtoff</value>
</field>
<field name="resolved">
<value>1289699151458</value>
</field>
<field name="permittedGroup">
<value>All Users</value>
</field>
<comment author="xtoff" text="Can you explain how that is problematic?
Also please update Affected version so that we're on the same page as to which version you're referring to.

I added a test that ensures this scenario is supported (i.e. - you can create such proxy, and it passes) http://github.com/castleproject/Castle.Core/commit/9b3c3929fdfe523c44a5a75e93ebe0f0648e4c05
" created="1285979709682" />
<comment author="rikard.pavelic" text="Maybe I'm doing something wrong, but if I do

generator.CreateClassProxy(typeof(ClassWithParamsArrayCtorArg), new object[] { "xxx", "aaa" });

I get an Could not find a constructor that would match given arguments
Reflection Activator works:

Activator.CreateInstance(typeof(ClassWithParamsArrayCtorArg), new object[] { "xxx", "aaa" });" created="1286066401244" />
<comment author="xtoff" text="I think you're confusing you class's constructor with {{generator.CreateClassProxy}}. {{CreteClassProxy}} takes arguments for your constructor as a normal array. And your ctor (I'm guessing) has a single argument - of type {{string[]}}. The fact that it's a params array is only a syntactic sugar for C# compiler.

In order to get this to work you should call it like this:

{{generator.CreateClassProxy(typeof(ClassWithParamsArrayCtorArg), new object[]{ new string[]{ "xxx", "aaa" } }); }}" created="1286081418760" />
<comment author="rikard.pavelic" text="It actually has more arguments and last one is params.
For classes:

public class ClassWithParamsArrayCtorArgPlain
{
 public ClassWithParamsArrayCtorArgPlain(int x, string[] arguments) { }
}
public class ClassWithParamsArrayCtorArgParams
{
 public ClassWithParamsArrayCtorArgParams(int x, params string[] arguments) { }
}

This will work in reflection:
Activator.CreateInstance(typeof(ClassWithParamsArrayCtorArgPlain), new object[] { 1, new[] { "xx", "aa" } });
Activator.CreateInstance(typeof(ClassWithParamsArrayCtorArgParams), new object[] { 1, new[] { "xx", "aa" } });
for arguments: int, string[]
Activator.CreateInstance(typeof(ClassWithParamsArrayCtorArgParams), new object[] { 1, "xx", "aa" });
for arguments: int, string, string, ....

This will not:
Activator.CreateInstance(typeof(ClassWithParamsArrayCtorArgPlain), new object[] { 1, "xx", "aa" });
because it can't find (int, string[])

Since DP uses Activator.CreateInstance to create instance of a proxy
it would behave the same if the params attribute was preserved in proxy class. But it's not." created="1286093157979" />
<comment author="xtoff" text="No, it wouldn't. {{params}} is only a C# compiler thing. You have to wrap your arguments in a {{object[]}} to get this to work. {{Activator.CreateInstance}} works in C# because it also has {{params}} argument." created="1286095817276" />
<comment author="rikard.pavelic" text="I think you're missing the point.

For this class

public class ClassWithParamsArrayCtorArg
{
 public ClassWithParamsArrayCtorArg(int x, params string[] arguments) { }
}

This is generic .NET code (without special C# features):

var type = typeof(ClassWithParamsArrayCtorArg);
var obj = new object[] { 1, "xxx", "aaa" };
var inst = Activator.CreateInstance(type, obj);
Assert.IsNotNull(inst);

This works. It doesn't need to be casted to new object[]{ 1, new string[]{"xxx","aaa"}}
It could be, but it doesn't need to be.

This is C# code:

var inst2 = Activator.CreateInstance(type, 1, "xxx", "aaa");
Assert.IsNotNull(inst2);

This works too, but only because of C# params support.

What is required for this to work is ParamArrayAttribute on last argument in constructor.
http://msdn.microsoft.com/en-us/library/system.paramarrayattribute.aspx
" created="1286097951401" />
<comment author="xtoff" text="sorry I misread your point. Yeah - looks like you're right. Interesting - I didn't know that {{Activator}} supports that :)" created="1286101927119" />
<comment author="xtoff" text="OK, I'm gonna queue it up for vNext, unless you want to give at shot at implementing it?
" created="1286158903869" />
<comment author="rikard.pavelic" text="Here it is.
I'm not very familiar with castle source, so I didn't try to integrate it too much.
And I don't have NUnit, so I didn't write tests for it :)" created="1286201457026" />
</issue>
</issues>