linux-packaging-mono/mcs/tests/gtest-optional-01.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

58 lines
1.0 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Reflection;
public class C
{
public static void TestA ([Optional][DefaultParameterValue (1)] int u)
{
}
public static void TestB (long u = 12)
{
}
public static void TestC (decimal d = decimal.MaxValue)
{
}
public static int Main ()
{
ParameterInfo[] info = typeof (C).GetMethod ("TestA").GetParameters ();
if (info[0].DefaultValue.GetType () != typeof (int))
return 1;
if ((int) info[0].DefaultValue != 1)
return 2;
if (!info[0].IsOptional)
return 3;
info = typeof (C).GetMethod ("TestB").GetParameters ();
if (info[0].DefaultValue.GetType () != typeof (long))
return 11;
if ((long) info[0].DefaultValue != 12)
return 12;
if (!info[0].IsOptional)
return 13;
info = typeof (C).GetMethod ("TestC").GetParameters ();
if (info[0].DefaultValue.GetType () != typeof (decimal))
return 21;
if ((decimal) info[0].DefaultValue != decimal.MaxValue)
return 22;
if (!info[0].IsOptional)
return 23;
Console.WriteLine ("ok");
return 0;
}
}