Exemple #1
0
    public static int test_0_dyncall_nullable()
    {
        int?v;

        v = 42;
        NullableMethods.GetHasValue(v);
        bool b = (bool)typeof(NullableMethods).GetMethod("GetHasValue").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { v });

        if (!b)
        {
            return(1);
        }
        v = null;
        b = (bool)typeof(NullableMethods).GetMethod("GetHasValue").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { v });
        if (b)
        {
            return(2);
        }

        v = 42;
        NullableMethods.GetValue(v);
        var res = (int)typeof(NullableMethods).GetMethod("GetValue").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { v });

        if (res != 42)
        {
            return(3);
        }
        return(0);
    }
Exemple #2
0
    public static int test_0_arm64_dyncall_vtypebyrefonstack()
    {
        var s = new LargeStruct()
        {
            a = 1, b = 2, c = 3, d = 4
        };

        NullableMethods.GetHasValueManyArgs <LargeStruct> (1, 2, 3, 4, 5, 6, 7, 8, s);

        Type type = typeof(LargeStruct?).GetGenericArguments() [0];
        var  m    = typeof(NullableMethods).GetMethod("GetHasValueManyArgs", BindingFlags.Static | BindingFlags.Public);
        bool b1   = (bool)m.MakeGenericMethod(new Type[] { type }).Invoke(null, new object[] { 1, 2, 3, 4, 5, 6, 7, 8, s });

        if (!b1)
        {
            return(1);
        }
        bool b2 = (bool)m.MakeGenericMethod(new Type[] { type }).Invoke(null, new object[] { 1, 2, 3, 4, 5, 6, 7, 8, null });

        if (b2)
        {
            return(2);
        }
        return(0);
    }
Exemple #3
0
    [Category("!WASM")]      //Interp fails
    public static int test_0_large_nullable_invoke()
    {
        var s = new LargeStruct()
        {
            a = 1, b = 2, c = 3, d = 4
        };

        NullableMethods.GetHasValue <LargeStruct> (s);

        var m = typeof(NullableMethods).GetMethod("GetHasValue", BindingFlags.Static | BindingFlags.Public);

        Type type = typeof(LargeStruct?).GetGenericArguments() [0];
        bool b1   = (bool)m.MakeGenericMethod(new Type[] { type }).Invoke(null, new object[] { s });

        if (!b1)
        {
            return(1);
        }
        bool b2 = (bool)m.MakeGenericMethod(new Type[] { type }).Invoke(null, new object[] { null });

        if (b2)
        {
            return(2);
        }
        return(0);
    }
Exemple #4
0
 static MethodInfo GetNullableValueMethod(this Type type)
 {
     type = type.GetNonNullableType();
     return(NullableMethods.GetOrAdd(type, key =>
                                     GetNullableValueMethodMethod.MakeGenericMethod(key)
                                     //NullableType.MakeGenericType(key).GetProperty("Value").GetGetMethod()
                                     ));
 }
Exemple #5
0
    public static int test_0_dyncall_nullable()
    {
        int?v;

        v = 42;
        NullableMethods.GetHasValue(v);
        bool b = (bool)typeof(NullableMethods).GetMethod("GetHasValue").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { v });

        if (!b)
        {
            return(1);
        }
        v = null;
        b = (bool)typeof(NullableMethods).GetMethod("GetHasValue").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { v });
        if (b)
        {
            return(2);
        }

        v = 42;
        NullableMethods.GetValue(v);
        var res = (int)typeof(NullableMethods).GetMethod("GetValue").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { v });

        if (res != 42)
        {
            return(3);
        }

        NullableMethods.Get(42);
        var res2 = (int?)typeof(NullableMethods).GetMethod("Get").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { 42 });

        if (res2 != 42)
        {
            return(4);
        }
        res2 = (int?)typeof(NullableMethods).GetMethod("GetNull").MakeGenericMethod(new Type [] { typeof(int) }).Invoke(null, new object [] { });
        if (res2.HasValue)
        {
            return(5);
        }

        NullableMethods.NullableMany(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8);
        res2 = (int?)typeof(NullableMethods).GetMethod("NullableMany").Invoke(null, new object [] { 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L });
        if (res2 != 36)
        {
            return(6);
        }
        return(0);
    }