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
.Generators
.Emitters
.SimpleAST
18 using System
.Reflection
;
19 using System
.Reflection
.Emit
;
21 public class NewInstanceExpression
: Expression
24 private Type
[] constructor_args
;
25 private Expression
[] arguments
;
26 private ConstructorInfo constructor
;
28 public NewInstanceExpression(ConstructorInfo constructor
, params Expression
[] args
)
30 this.constructor
= constructor
;
34 public NewInstanceExpression(Type target
, Type
[] constructor_args
, params Expression
[] args
)
37 this.constructor_args
= constructor_args
;
41 public override void Emit(IMemberEmitter member
, ILGenerator gen
)
43 foreach(Expression exp
in arguments
)
45 exp
.Emit(member
, gen
);
48 if (constructor
== null)
50 constructor
= type
.GetConstructor(constructor_args
);
53 if (constructor
== null)
55 throw new ApplicationException("Could not find constructor matching specified arguments");
58 gen
.Emit(OpCodes
.Newobj
, constructor
);