1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.DynamicProxy
.Builder
.CodeBuilder
.Utils
18 using System
.Reflection
;
19 using System
.Reflection
.Emit
;
21 using Castle
.DynamicProxy
.Builder
.CodeBuilder
.SimpleAST
;
24 /// Summary description for ArgumentsUtil.
27 public abstract class ArgumentsUtil
29 public static void EmitLoadOwnerAndReference(Reference reference
, ILGenerator il
)
31 if (reference
== null) return;
33 EmitLoadOwnerAndReference(reference
.OwnerReference
, il
);
35 reference
.LoadReference(il
);
38 public static void InitializeArgumentsByPosition(ArgumentReference
[] args
)
40 for(int i
=0; i
< args
.Length
; ++i
)
42 args
[i
].Position
= i
+1;
46 public static Type
[] InitializeAndConvert(ArgumentReference
[] args
)
48 Type
[] types
= new Type
[args
.Length
];
50 for(int i
=0; i
< args
.Length
; ++i
)
52 args
[i
].Position
= i
+1;
53 types
[i
] = args
[i
].Type
;
59 public static ArgumentReference
[] ConvertToArgumentReference(Type
[] args
)
61 ArgumentReference
[] arguments
= new ArgumentReference
[args
.Length
];
63 for(int i
=0; i
< args
.Length
; ++i
)
65 arguments
[i
] = new ArgumentReference( args
[i
] );
71 public static ArgumentReference
[] ConvertToArgumentReference(ParameterInfo
[] args
)
73 ArgumentReference
[] arguments
= new ArgumentReference
[args
.Length
];
75 for(int i
=0; i
< args
.Length
; ++i
)
77 arguments
[i
] = new ArgumentReference( args
[i
].ParameterType
);
83 public static Expression
[] ConvertArgumentReferenceToExpression(ArgumentReference
[] args
)
85 Expression
[] expressions
= new Expression
[args
.Length
];
87 for(int i
=0; i
< args
.Length
; ++i
)
89 expressions
[i
] = args
[i
].ToExpression();