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
.Test
18 using System
.Collections
;
19 using System
.Collections
.Specialized
;
20 using System
.Reflection
;
21 using System
.Diagnostics
;
22 using System
.Reflection
.Emit
;
24 using Castle
.DynamicProxy
.Builder
.CodeBuilder
;
25 using Castle
.DynamicProxy
.Builder
.CodeGenerators
;
26 using Castle
.DynamicProxy
.Builder
.CodeBuilder
.SimpleAST
;
28 using NUnit
.Framework
;
29 using Castle
.DynamicProxy
.Test
.Classes
;
30 using System
.Threading
;
33 public class EasyTypeBuilderTestCase
40 module
= new ModuleScope();
43 public void RunPEVerify()
46 if (module
.SaveAssembly())
48 Process process
= new Process();
49 process
.StartInfo
.UseShellExecute
= false;
50 process
.StartInfo
.RedirectStandardOutput
= true;
51 process
.StartInfo
.Arguments
= ModuleScope
.FILE_NAME
;
52 // Hack. Should it find in the path?
53 // I thought it would.
54 process
.StartInfo
.FileName
= @"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\PEVerify.exe";
56 process
.WaitForExit( Int32
.MaxValue
);
57 if (process
.ExitCode
!= 0)
59 Assert
.Fail( process
.StandardOutput
.ReadToEnd() );
66 public void CreateSimpleType()
68 EasyType typebuilder
= new EasyType( module
, "mytype" );
70 Type newType
= typebuilder
.BuildType();
71 Assert
.IsNotNull( newType
);
72 object instance
= Activator
.CreateInstance( newType
);
73 Assert
.IsNotNull( instance
);
79 public void CreateSimpleTypeWithExplicitDefaultConstructor()
81 EasyType typebuilder
= new EasyType( module
, "mytype" );
82 typebuilder
.CreateDefaultConstructor();
84 Type newType
= typebuilder
.BuildType();
85 Assert
.IsNotNull( newType
);
86 object instance
= Activator
.CreateInstance( newType
);
87 Assert
.IsNotNull( instance
);
93 public void CreateSimpleTypeWithConstructor()
95 EasyType typebuilder
= new EasyType( module
, "mytype" );
97 ArgumentReference arg1
= new ArgumentReference( typeof(String
) );
98 ArgumentReference arg2
= new ArgumentReference( typeof(int) );
100 typebuilder
.CreateConstructor( arg1
, arg2
);
102 Type newType
= typebuilder
.BuildType();
103 Assert
.IsNotNull( newType
);
104 object instance
= Activator
.CreateInstance( newType
, new object[] { "message", 10 }
);
105 Assert
.IsNotNull( instance
);
111 public void EmptyMethodReturningVoid()
113 EasyType typebuilder
= new EasyType( module
, "mytype" );
115 EasyMethod emptyMethod
= typebuilder
.CreateMethod( "DoSomething",
116 new ReturnReferenceExpression( typeof(void) ) );
118 Type newType
= typebuilder
.BuildType();
119 Assert
.IsNotNull( newType
);
120 object instance
= Activator
.CreateInstance( newType
);
121 Assert
.IsNotNull( instance
);
123 MethodInfo method
= instance
.GetType().GetMethod("DoSomething");
124 method
.Invoke( instance
, new object[0] );
130 public void EmptyMethodReturningInt()
132 EasyType typebuilder
= new EasyType( module
, "mytype" );
134 EasyMethod emptyMethod
= typebuilder
.CreateMethod( "DoSomething",
135 new ReturnReferenceExpression(typeof(int)) );
137 Type newType
= typebuilder
.BuildType();
138 Assert
.IsNotNull( newType
);
139 object instance
= Activator
.CreateInstance( newType
);
140 Assert
.IsNotNull( instance
);
142 MethodInfo method
= instance
.GetType().GetMethod("DoSomething");
143 Assert
.AreEqual( 0, method
.Invoke( instance
, new object[0] ) );
149 public void MethodCalc()
151 EasyType typebuilder
= new EasyType( module
, "mytype" );
153 ArgumentReference arg1
= new ArgumentReference(typeof(int));
154 ArgumentReference arg2
= new ArgumentReference(typeof(int));
155 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(int));
157 EasyMethod calcMethod
= typebuilder
.CreateMethod( "Calc", ret
, arg1
, arg2
);
159 calcMethod
.CodeBuilder
.AddStatement(
161 new BinaryExpression( BinaryExpression
.Add
, arg1
.ToExpression(), arg2
.ToExpression() ) ) );
163 Type newType
= typebuilder
.BuildType();
164 Assert
.IsNotNull( newType
);
165 object instance
= Activator
.CreateInstance( newType
);
166 Assert
.IsNotNull( instance
);
168 MethodInfo method
= instance
.GetType().GetMethod("Calc");
169 Assert
.AreEqual( 2, method
.Invoke( instance
, new object[] { 1,1 }
) );
170 Assert
.AreEqual( 5, method
.Invoke( instance
, new object[] { 3,2 }
) );
176 public void FieldsStoreAndLoad()
178 EasyType typebuilder
= new EasyType( module
, "mytype" );
180 FieldReference field1
= typebuilder
.CreateField( "field1", typeof(int) );
181 FieldReference field2
= typebuilder
.CreateField( "field2", typeof(string) );
184 ArgumentReference arg1
= new ArgumentReference(typeof(int));
185 ArgumentReference arg2
= new ArgumentReference(typeof(string));
187 EasyConstructor constr
= typebuilder
.CreateConstructor( arg1
, arg2
);
188 constr
.CodeBuilder
.InvokeBaseConstructor();
189 constr
.CodeBuilder
.AddStatement( new AssignStatement( field1
, arg1
.ToExpression() ) );
190 constr
.CodeBuilder
.AddStatement( new AssignStatement( field2
, arg2
.ToExpression() ) );
191 constr
.CodeBuilder
.AddStatement( new ReturnStatement() );
195 ReturnReferenceExpression ret1
= new ReturnReferenceExpression( typeof(int) );
196 EasyMethod m1
= typebuilder
.CreateMethod( "GetField1", ret1
);
197 m1
.CodeBuilder
.AddStatement( new ReturnStatement( field1
) );
199 ReturnReferenceExpression ret2
= new ReturnReferenceExpression( typeof(string) );
200 EasyMethod m2
= typebuilder
.CreateMethod( "GetField2", ret2
);
201 m2
.CodeBuilder
.AddStatement( new ReturnStatement( field2
) );
204 Type newType
= typebuilder
.BuildType();
205 Assert
.IsNotNull( newType
);
206 object instance
= Activator
.CreateInstance( newType
, new object[] { 10, "hello" }
);
207 Assert
.IsNotNull( instance
);
209 MethodInfo method1
= instance
.GetType().GetMethod("GetField1");
210 MethodInfo method2
= instance
.GetType().GetMethod("GetField2");
211 Assert
.AreEqual( 10, method1
.Invoke( instance
, new object[0] ));
212 Assert
.AreEqual( "hello", method2
.Invoke( instance
, new object[0] ));
218 public void MethodInvokingMethod()
220 EasyType typebuilder
= new EasyType( module
, "mytype" );
222 ArgumentReference rarg1
= new ArgumentReference(typeof(int));
223 ArgumentReference rarg2
= new ArgumentReference(typeof(int));
224 ReturnReferenceExpression rret
= new ReturnReferenceExpression(typeof(int));
225 EasyMethod realCalcMethod
= typebuilder
.CreateMethod( "RealCalc", rret
, rarg1
, rarg2
);
226 realCalcMethod
.CodeBuilder
.AddStatement(
228 new BinaryExpression( BinaryExpression
.Add
, rarg1
.ToExpression(), rarg2
.ToExpression() ) ) );
230 ArgumentReference arg1
= new ArgumentReference(typeof(int));
231 ArgumentReference arg2
= new ArgumentReference(typeof(int));
232 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(int));
233 EasyMethod calcMethod
= typebuilder
.CreateMethod( "Calc", ret
, arg1
, arg2
);
234 calcMethod
.CodeBuilder
.AddStatement(
236 new MethodInvocationExpression( realCalcMethod
, arg1
.ToExpression(), arg2
.ToExpression() ) ) );
238 Type newType
= typebuilder
.BuildType();
239 Assert
.IsNotNull( newType
);
240 object instance
= Activator
.CreateInstance( newType
, new object[0] );
241 Assert
.IsNotNull( instance
);
243 MethodInfo method
= instance
.GetType().GetMethod("Calc");
244 Assert
.AreEqual( 2, method
.Invoke( instance
, new object[] { 1,1 }
) );
245 Assert
.AreEqual( 5, method
.Invoke( instance
, new object[] { 3,2 }
) );
246 method
= instance
.GetType().GetMethod("RealCalc");
247 Assert
.AreEqual( 2, method
.Invoke( instance
, new object[] { 1,1 }
) );
248 Assert
.AreEqual( 5, method
.Invoke( instance
, new object[] { 3,2 }
) );
254 public void NewInstanceExpression()
256 EasyType typebuilder
= new EasyType( module
, "mytype" );
258 FieldReference cachefield
= typebuilder
.CreateField( "cache", typeof(ArrayList
) );
260 EasyConstructor constructor
= typebuilder
.CreateConstructor( );
261 constructor
.CodeBuilder
.InvokeBaseConstructor();
262 constructor
.CodeBuilder
.AddStatement( new AssignStatement(cachefield
,
263 new NewInstanceExpression( typeof(ArrayList
), new Type
[0] ) ) );
264 constructor
.CodeBuilder
.AddStatement( new ReturnStatement() );
266 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(ArrayList
));
267 EasyMethod getCache
= typebuilder
.CreateMethod( "GetCache", ret
);
268 getCache
.CodeBuilder
.AddStatement( new ReturnStatement( cachefield
) );
270 Type newType
= typebuilder
.BuildType();
271 Assert
.IsNotNull( newType
);
272 object instance
= Activator
.CreateInstance( newType
, new object[0] );
273 Assert
.IsNotNull( instance
);
275 MethodInfo method
= instance
.GetType().GetMethod("GetCache");
276 Assert
.IsNotNull( method
.Invoke( instance
, new object[0] ) );
282 public void BlockWithLock()
284 EasyType typebuilder
= new EasyType( module
, "mytype" );
286 FieldReference cachefield
= typebuilder
.CreateField( "cache", typeof(ArrayList
) );
288 EasyConstructor constructor
= typebuilder
.CreateConstructor( );
289 constructor
.CodeBuilder
.InvokeBaseConstructor();
291 LockBlockExpression block
= new LockBlockExpression( SelfReference
.Self
);
293 block
.AddStatement( new AssignStatement(cachefield
,
294 new NewInstanceExpression( typeof(ArrayList
), new Type
[0] ) ) );
296 constructor
.CodeBuilder
.AddStatement( new ExpressionStatement(block
) );
297 constructor
.CodeBuilder
.AddStatement( new ReturnStatement() );
299 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(ArrayList
));
300 EasyMethod getCache
= typebuilder
.CreateMethod( "GetCache", ret
);
301 getCache
.CodeBuilder
.AddStatement( new ReturnStatement( cachefield
) );
303 Type newType
= typebuilder
.BuildType();
304 Assert
.IsNotNull( newType
);
305 object instance
= Activator
.CreateInstance( newType
, new object[0] );
306 Assert
.IsNotNull( instance
);
308 MethodInfo method
= instance
.GetType().GetMethod("GetCache");
309 Assert
.IsNotNull( method
.Invoke( instance
, new object[0] ) );
315 public void Conditionals()
317 EasyType typebuilder
= new EasyType( module
, "mytype" );
319 FieldReference cachefield
= typebuilder
.CreateField( "cache", typeof(IDictionary
) );
321 ArgumentReference arg
= new ArgumentReference( typeof(bool) );
323 EasyConstructor constructor
= typebuilder
.CreateConstructor( arg
);
324 constructor
.CodeBuilder
.InvokeBaseConstructor();
326 ConditionExpression exp
= new ConditionExpression(OpCodes
.Brtrue_S
, arg
.ToExpression());
327 exp
.AddTrueStatement( new AssignStatement(cachefield
,
328 new NewInstanceExpression( typeof(HybridDictionary
), new Type
[0] ) ) );
329 exp
.AddFalseStatement( new AssignStatement(cachefield
,
330 new NewInstanceExpression( typeof(Hashtable
), new Type
[0] ) ) );
332 constructor
.CodeBuilder
.AddStatement( new ExpressionStatement(exp
) );
333 constructor
.CodeBuilder
.AddStatement( new ReturnStatement() );
335 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(IDictionary
));
336 EasyMethod getCache
= typebuilder
.CreateMethod( "GetCache", ret
);
337 getCache
.CodeBuilder
.AddStatement( new ReturnStatement( cachefield
) );
339 Type newType
= typebuilder
.BuildType();
340 object instance
= Activator
.CreateInstance( newType
, new object[] { true }
);
341 MethodInfo method
= instance
.GetType().GetMethod("GetCache");
342 object dic
= method
.Invoke( instance
, new object[0] );
343 Assert
.IsTrue( dic
is HybridDictionary
);
345 instance
= Activator
.CreateInstance( newType
, new object[] { false }
);
346 dic
= method
.Invoke( instance
, new object[0] );
347 Assert
.IsTrue( dic
is Hashtable
);
353 public void ArrayRefs()
355 EasyType typebuilder
= new EasyType( module
, "mytype" );
357 FieldReference field1
= typebuilder
.CreateField( "field1", typeof(object) );
358 FieldReference field2
= typebuilder
.CreateField( "field2", typeof(object) );
360 ArgumentReference arg
= new ArgumentReference( typeof(object[]) );
362 EasyConstructor constructor
= typebuilder
.CreateConstructor( arg
);
363 constructor
.CodeBuilder
.InvokeBaseConstructor();
365 constructor
.CodeBuilder
.AddStatement( new AssignStatement(field1
,
366 new LoadRefArrayElementExpression( 0, arg
) ) );
367 constructor
.CodeBuilder
.AddStatement( new AssignStatement(field2
,
368 new LoadRefArrayElementExpression( 1, arg
) ) );
370 constructor
.CodeBuilder
.AddStatement( new ReturnStatement() );
372 ReturnReferenceExpression ret1
= new ReturnReferenceExpression(typeof(object));
373 EasyMethod getField1
= typebuilder
.CreateMethod( "GetField1", ret1
);
374 getField1
.CodeBuilder
.AddStatement( new ReturnStatement( field1
) );
376 ReturnReferenceExpression ret2
= new ReturnReferenceExpression(typeof(object));
377 EasyMethod getField2
= typebuilder
.CreateMethod( "GetField2", ret2
);
378 getField2
.CodeBuilder
.AddStatement( new ReturnStatement( field2
) );
380 Type newType
= typebuilder
.BuildType();
381 object[] innerArgs
= new object[] { "hammett", "verissimo" }
;
382 object instance
= Activator
.CreateInstance( newType
, new object[] { innerArgs }
);
384 MethodInfo method
= instance
.GetType().GetMethod("GetField1");
385 object result
= method
.Invoke( instance
, new object[0] );
386 Assert
.AreEqual( "hammett", result
);
388 method
= instance
.GetType().GetMethod("GetField2");
389 result
= method
.Invoke( instance
, new object[0] );
390 Assert
.AreEqual( "verissimo", result
);
396 public void CreateCallable()
398 EasyType typebuilder
= new EasyType( module
, "mytype" );
399 EasyCallable callable
= typebuilder
.CreateCallable( new ReturnReferenceExpression(typeof(string)) );
401 FieldReference field1
= typebuilder
.CreateField( "field1", callable
.TypeBuilder
);
403 SimpleCallback sc
= new SimpleCallback();
405 ArgumentReference arg
= new ArgumentReference( typeof(SimpleCallback
) );
406 EasyConstructor constructor
= typebuilder
.CreateConstructor( arg
);
407 constructor
.CodeBuilder
.InvokeBaseConstructor();
409 constructor
.CodeBuilder
.AddStatement( new AssignStatement(field1
,
410 new NewInstanceExpression( callable
,
412 new MethodPointerExpression( arg
, typeof(SimpleCallback
).GetMethod("Run") ) ) ) );
414 constructor
.CodeBuilder
.AddStatement( new ReturnStatement() );
416 ReturnReferenceExpression ret1
= new ReturnReferenceExpression(typeof(string));
417 EasyMethod getField1
= typebuilder
.CreateMethod( "Exec", ret1
);
418 getField1
.CodeBuilder
.AddStatement(
420 new ConvertExpression( typeof(String
),
421 new MethodInvocationExpression( field1
,
423 new ReferencesToObjectArrayExpression() ) ) ) );
425 Type newType
= typebuilder
.BuildType();
429 object instance
= Activator
.CreateInstance( newType
, new object[] { sc }
);
431 MethodInfo method
= instance
.GetType().GetMethod("Exec");
432 object result
= method
.Invoke( instance
, new object[0] );
433 Assert
.AreEqual( "hello", result
);
437 public void CreateMoreComplexCallable()
439 EasyType typebuilder
= new EasyType( module
, "mytype" );
441 ArgumentReference arg1
= new ArgumentReference( typeof(int) );
442 ArgumentReference arg2
= new ArgumentReference( typeof(DateTime
) );
443 ArgumentReference arg3
= new ArgumentReference( typeof(object) );
444 EasyCallable callable
= typebuilder
.CreateCallable(
445 new ReturnReferenceExpression(typeof(string)),
448 FieldReference field1
= typebuilder
.CreateField( "field1", callable
.TypeBuilder
);
450 SimpleCallback sc
= new SimpleCallback();
452 ArgumentReference arg
= new ArgumentReference( typeof(SimpleCallback
) );
453 EasyConstructor constructor
= typebuilder
.CreateConstructor( arg
);
454 constructor
.CodeBuilder
.InvokeBaseConstructor();
456 constructor
.CodeBuilder
.AddStatement( new AssignStatement(field1
,
457 new NewInstanceExpression( callable
,
459 new MethodPointerExpression( arg
, typeof(SimpleCallback
).GetMethod("RunAs") ) ) ) );
461 constructor
.CodeBuilder
.AddStatement( new ReturnStatement() );
463 arg1
= new ArgumentReference( typeof(int) );
464 arg2
= new ArgumentReference( typeof(DateTime
) );
465 arg3
= new ArgumentReference( typeof(object) );
467 ReturnReferenceExpression ret1
= new ReturnReferenceExpression(typeof(string));
469 EasyMethod getField1
= typebuilder
.CreateMethod( "Exec", ret1
, arg1
, arg2
, arg3
);
470 getField1
.CodeBuilder
.AddStatement(
472 new ConvertExpression( typeof(String
),
473 new MethodInvocationExpression( field1
,
475 new ReferencesToObjectArrayExpression(arg1
, arg2
, arg3
) ) ) ) );
477 Type newType
= typebuilder
.BuildType();
481 object instance
= Activator
.CreateInstance( newType
, new object[] { sc }
);
483 MethodInfo method
= instance
.GetType().GetMethod("Exec");
484 object result
= method
.Invoke( instance
, new object[] { 1, DateTime.Now, "" }
);
485 Assert
.AreEqual( "hello2", result
);
488 public class SimpleCallback
495 public String
RunAs(int value, DateTime dt
, object placeholder
)
502 public void EmptyMethodWithPrimitiveTypeRefArg()
504 EasyType typebuilder
= new EasyType( module
, "mytype" );
507 Type refType
= GetPrimitiveRefType(ref refArgInst
);
509 ArgumentReference refArg
= new ArgumentReference( refType
);
510 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(int));
512 EasyMethod emptyMethod
= typebuilder
.CreateMethod( "DoSomething", ret
, refArg
);
514 Type newType
= typebuilder
.BuildType();
515 Assert
.IsNotNull( newType
);
516 object instance
= Activator
.CreateInstance( newType
);
517 Assert
.IsNotNull( instance
);
519 MethodInfo method
= instance
.GetType().GetMethod("DoSomething");
520 method
.Invoke( instance
, new object[]{refArgInst}
);
522 Assert
.AreEqual(42, refArgInst
, "Argument made round-trip successfully");
528 public void EmptyMethodWithReferenceTypeRefArg()
530 EasyType typebuilder
= new EasyType(module
, "mytype");
532 string refArgInst
= "foobar";
533 Type refType
= GetReferenceRefType(ref refArgInst
);
535 ArgumentReference refArg
= new ArgumentReference(refType
);
536 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(int));
538 EasyMethod emptyMethod
= typebuilder
.CreateMethod("DoSomething", ret
, refArg
);
540 Type newType
= typebuilder
.BuildType();
541 Assert
.IsNotNull(newType
);
542 object instance
= Activator
.CreateInstance(newType
);
543 Assert
.IsNotNull(instance
);
545 MethodInfo method
= instance
.GetType().GetMethod("DoSomething");
546 method
.Invoke(instance
, new object[] { refArgInst }
);
548 Assert
.AreEqual("foobar", refArgInst
, "Argument made round-trip successfully");
554 public void EmptyMethodWithStructTypeRefArg()
556 EasyType typebuilder
= new EasyType(module
, "mytype");
558 DateTime refArgInst
= new DateTime(2005, 1, 1);
559 Type refType
= GetStructRefType(ref refArgInst
);
561 Assert
.IsTrue(refType
.IsByRef
);
563 ArgumentReference refArg
= new ArgumentReference(refType
);
564 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(int));
566 EasyMethod emptyMethod
= typebuilder
.CreateMethod("DoSomething", ret
, refArg
);
568 Type newType
= typebuilder
.BuildType();
569 Assert
.IsNotNull(newType
);
570 object instance
= Activator
.CreateInstance(newType
);
571 Assert
.IsNotNull(instance
);
573 MethodInfo method
= instance
.GetType().GetMethod("DoSomething");
574 method
.Invoke(instance
, new object[] { refArgInst }
);
576 Assert
.AreEqual(new DateTime(2005, 1, 1), refArgInst
, "Argument made round-trip successfully");
582 public void EmptyMethodWithEnumTypeRefArg()
584 EasyType typebuilder
= new EasyType(module
, "mytype");
586 SByteEnum refArgInst
= SByteEnum
.Two
;
587 Type refType
= GetEnumRefType(ref refArgInst
);
589 Assert
.IsTrue(refType
.IsByRef
);
591 ArgumentReference refArg
= new ArgumentReference(refType
);
592 ReturnReferenceExpression ret
= new ReturnReferenceExpression(typeof(int));
594 EasyMethod emptyMethod
= typebuilder
.CreateMethod("DoSomething", ret
, refArg
);
596 Type newType
= typebuilder
.BuildType();
597 Assert
.IsNotNull(newType
);
598 object instance
= Activator
.CreateInstance(newType
);
599 Assert
.IsNotNull(instance
);
601 MethodInfo method
= instance
.GetType().GetMethod("DoSomething");
602 method
.Invoke(instance
, new object[] { refArgInst }
);
604 Assert
.AreEqual(SByteEnum
.Two
, refArgInst
, "Argument made round-trip successfully");
609 public Type
GetPrimitiveRefType(ref int refArg
)
611 // Need this because .Net 1.1 does not have the Type.MakeByRefType method.
612 ParameterInfo
[] parameters
= this.GetType().GetMethod("GetPrimitiveRefType").GetParameters();
613 Assert
.AreEqual(1, parameters
.Length
);
614 Type refType
= parameters
[0].ParameterType
;
615 Assert
.IsTrue(refType
.IsByRef
);
619 public Type
GetReferenceRefType(ref string refArg
)
621 // Need this because .Net 1.1 does not have the Type.MakeByRefType method.
622 ParameterInfo
[] parameters
= this.GetType().GetMethod("GetReferenceRefType").GetParameters();
623 Assert
.AreEqual(1, parameters
.Length
);
624 Type refType
= parameters
[0].ParameterType
;
625 Assert
.IsTrue(refType
.IsByRef
);
629 public Type
GetStructRefType(ref DateTime refArg
)
631 // Need this because .Net 1.1 does not have the Type.MakeByRefType method.
632 ParameterInfo
[] parameters
= this.GetType().GetMethod("GetStructRefType").GetParameters();
633 Assert
.AreEqual(1, parameters
.Length
);
634 Type refType
= parameters
[0].ParameterType
;
635 Assert
.IsTrue(refType
.IsByRef
);
639 public Type
GetEnumRefType(ref SByteEnum refArg
)
641 // Need this because .Net 1.1 does not have the Type.MakeByRefType method.
642 ParameterInfo
[] parameters
= this.GetType().GetMethod("GetEnumRefType").GetParameters();
643 Assert
.AreEqual(1, parameters
.Length
);
644 Type refType
= parameters
[0].ParameterType
;
645 Assert
.IsTrue(refType
.IsByRef
);