2 // ParameterInfoTest - NUnit Test Cases for the ParameterInfo class
4 // Zoltan Varga (vargaz@freemail.hu)
6 // (C) Ximian, Inc. http://www.ximian.com
11 using System
.Threading
;
12 using System
.Reflection
;
13 using System
.Reflection
.Emit
;
14 using System
.Runtime
.InteropServices
;
16 using NUnit
.Framework
;
18 namespace MonoTests
.System
.Reflection
22 public class Marshal1
: ICustomMarshaler
24 public static ICustomMarshaler
GetInstance (string s
) {
25 return new Marshal1 ();
28 public void CleanUpManagedData (object managedObj
)
32 public void CleanUpNativeData (IntPtr pNativeData
)
36 public int GetNativeDataSize ()
41 public IntPtr
MarshalManagedToNative (object managedObj
)
46 public object MarshalNativeToManaged (IntPtr pNativeData
)
53 public class ParameterInfoTest
: Assertion
55 public static void paramMethod (int i
, [In
] int j
, [Out
] int k
, [Optional
] int l
, [In
,Out
] int m
) {
59 public extern static void marshalAsMethod (
60 [MarshalAs(UnmanagedType
.Bool
)]int p0
,
61 [MarshalAs(UnmanagedType
.LPArray
, ArraySubType
=UnmanagedType
.LPStr
)] string [] p1
,
62 [MarshalAs( UnmanagedType
.CustomMarshaler
, MarshalTypeRef
= typeof (Marshal1
), MarshalCookie
= "5")] object p2
);
66 public void PseudoCustomAttributes () {
67 ParameterInfo
[] info
= typeof (ParameterInfoTest
).GetMethod ("paramMethod").GetParameters ();
68 AssertEquals (0, info
[0].GetCustomAttributes (true).Length
);
69 AssertEquals (1, info
[1].GetCustomAttributes (typeof (InAttribute
), true).Length
);
70 AssertEquals (1, info
[2].GetCustomAttributes (typeof (OutAttribute
), true).Length
);
71 AssertEquals (1, info
[3].GetCustomAttributes (typeof (OptionalAttribute
), true).Length
);
72 AssertEquals (2, info
[4].GetCustomAttributes (true).Length
);
74 ParameterInfo
[] pi
= typeof (ParameterInfoTest
).GetMethod ("marshalAsMethod").GetParameters ();
75 MarshalAsAttribute attr
;
77 attr
= (MarshalAsAttribute
)(pi
[0].GetCustomAttributes (true) [0]);
78 AssertEquals (UnmanagedType
.Bool
, attr
.Value
);
80 attr
= (MarshalAsAttribute
)(pi
[1].GetCustomAttributes (true) [0]);
81 AssertEquals (UnmanagedType
.LPArray
, attr
.Value
);
82 AssertEquals (UnmanagedType
.LPStr
, attr
.ArraySubType
);
84 attr
= (MarshalAsAttribute
)(pi
[2].GetCustomAttributes (true) [0]);
85 AssertEquals (UnmanagedType
.CustomMarshaler
, attr
.Value
);
86 AssertEquals ("5", attr
.MarshalCookie
);
87 AssertEquals (typeof (Marshal1
), Type
.GetType (attr
.MarshalType
));