示例#1
0
文件: generics.cs 项目: zer09/Cosmos
    public static int test_0_ldfld_stfld_mro()
    {
        MRO m = new MRO();
        GenericStruct <int> s = new GenericStruct <int>(5);

        // This generates stfld
        m.struct_field = s;

        // This generates ldflda
        if (m.struct_field.t != 5)
        {
            return(1);
        }

        // This generates ldfld
        GenericStruct <int> s2 = m.struct_field;

        if (s2.t != 5)
        {
            return(2);
        }

        if (m.struct_field.t != 5)
        {
            return(3);
        }

        m.class_field = new GenericClass <int>(5);
        if (m.class_field.t != 5)
        {
            return(4);
        }

        return(0);
    }
示例#2
0
        public static void Sample()
        {
            Console.WriteLine("---------- Generic.Where ----------");

            Employee emp = new Employee();

            emp.Name = "Test001";
            SubEmployee <Employee> class1 = new SubEmployee <Employee>(emp);

            class1.Print();

            GenericStruct <Struct> gs = new GenericStruct <Struct>();             // ok.
            //GenericStruct<Class> gs_error = new GenericStruct<Class>(); // error
            GenericClass <Class> gc = new GenericClass <Class>();                 // ok.
            //GenericClass<Struct> gc_error = new GenericClass<Struct>(); // error
            GenericNew <New> gn = new GenericNew <New>();                         // ok.
            //GenericNew<Interface> gn_error = new GenericNew<Interface>(); // error
            GenericBase <Base> gb = new GenericBase <Base>();                     // ok.
            //GenericBase<Class> gb_error = new GenericBase<Class>(); // error
            GenericInterface <Interface> gi = new GenericInterface <Interface>(); // ok
            //GenericInterface<Class> gi_error = new GenericInterface<Class>(); // error
            GenericU <TClass, UClass> gu = new GenericU <TClass, UClass>();       // ok

            //GenericU<VClass, UClass> gu_error = new GenericU<VClass, UClass>(); // error

            Console.WriteLine("\n");
        }
	public static int test_0_ldfld_stfld_mro () {
		MRO m = new MRO ();
		GenericStruct<int> s = new GenericStruct<int> (5);
		// This generates stfld
		m.struct_field = s;

		// This generates ldflda
		if (m.struct_field.t != 5)
			return 1;

		// This generates ldfld
		GenericStruct<int> s2 = m.struct_field;
		if (s2.t != 5)
			return 2;

		if (m.struct_field.t != 5)
			return 3;

		m.class_field = new GenericClass<int> (5);
		if (m.class_field.t != 5)
			return 4;

		// gshared
		var m2 = new MRO<string> ();
		if (m2.stfld_ldfld ("A") != "A")
			return 5;

		return 0;
	}
示例#4
0
        public void Add <T>(Event key, T value, Color color) where T : class
        {
            GenericStruct tempStruct = new GenericStruct();

            tempStruct.Init(key, value);
            tempStruct.SetColour(color);
            genericEventList.Add(tempStruct);
        }
示例#5
0
文件: debugger-test.cs 项目: cpw/mono
    public static int DelegatesSignatureTest()
    {
        Func <Math, GenericStruct <GenericStruct <int[]> >, GenericStruct <bool[]> > fn_func      = (m, gs) => new GenericStruct <bool[]>();
        Func <Math, GenericStruct <GenericStruct <int[]> >, GenericStruct <bool[]> > fn_func_del  = GenericStruct <int> .DelegateTargetForSignatureTest;
        Func <Math, GenericStruct <GenericStruct <int[]> >, GenericStruct <bool[]> > fn_func_null = null;
        Func <bool> fn_func_only_ret = () => { Console.WriteLine($"hello"); return(true); };
        var         fn_func_arr      = new Func <Math, GenericStruct <GenericStruct <int[]> >, GenericStruct <bool[]> >[] { (m, gs) => new GenericStruct <bool[]>() };

        Math.DelegateForSignatureTest fn_del   = GenericStruct <int> .DelegateTargetForSignatureTest;
        Math.DelegateForSignatureTest fn_del_l = (m, gs) => new GenericStruct <bool[]> {
            StringField = "fn_del_l#lambda"
        };
        var fn_del_arr = new Math.DelegateForSignatureTest[] { GenericStruct <int> .DelegateTargetForSignatureTest, (m, gs) => new GenericStruct <bool[]> {
                                                                   StringField = "fn_del_arr#1#lambda"
                                                               } };
        var m_obj = new Math();

        Math.DelegateForSignatureTest fn_del_null = null;
        var gs_gs = new GenericStruct <GenericStruct <int[]> >
        {
            List = new System.Collections.Generic.List <GenericStruct <int[]> > {
                new GenericStruct <int[]> {
                    StringField = "gs#List#0#StringField"
                },
                new GenericStruct <int[]> {
                    StringField = "gs#List#1#StringField"
                }
            }
        };

        Math.DelegateWithVoidReturn fn_void_del = Math.DelegateTargetWithVoidReturn;
        var fn_void_del_arr = new Math.DelegateWithVoidReturn[] { Math.DelegateTargetWithVoidReturn };

        Math.DelegateWithVoidReturn fn_void_del_null = null;

        var rets = new GenericStruct <bool[]>[] {
            fn_func(m_obj, gs_gs),
            fn_func_del(m_obj, gs_gs),
            fn_del(m_obj, gs_gs),
            fn_del_l(m_obj, gs_gs),
            fn_del_arr[0] (m_obj, gs_gs),
            fn_func_arr[0] (m_obj, gs_gs)
        };

        var gs = new GenericStruct <int[]>();

        fn_void_del(gs);
        fn_void_del_arr[0](gs);
        fn_func_only_ret();
        foreach (var ret in rets)
        {
            Console.WriteLine($"ret: {ret}");
        }
        OuterMethod();
        Console.WriteLine($"- {gs_gs.List[0].StringField}");
        return(0);
    }
            public Task <bool> AsyncMethodWithStructArgs(GenericStruct <int> gs)
            {
                Console.WriteLine($"placeholder line for a breakpoint");
                if (gs.List.Count > 0)
                {
                    return(Task.FromResult(true));
                }

                return(Task.FromResult(false));
            }
        public void GenericStructTest()
        {
            var t = new GenericStruct <int, string> {
                MyProperty0 = 100, MyProperty1 = "aaa"
            };
            var v = Convert(t);

            v.MyProperty0.Is(100);
            v.MyProperty1.Is("aaa");
        }
示例#8
0
        public void TestGenericStruct()
        {
            TestStruct testStruct   = new TestStruct(10, 20);
            var        objectNewInt = new GenericStruct <TestStruct>(testStruct);

            Assert.That(objectNewInt.Data, Is.Not.SameAs(testStruct));
            Assert.That(objectNewInt.Data.X, Is.EqualTo(testStruct.X));
            Assert.That(objectNewInt.Data.Y, Is.EqualTo(testStruct.Y));

            Assert.That(new GenericStruct <int>(10).Data, Is.EqualTo(10));
        }
示例#9
0
        public static void MethodWithStructs()
        {
            var ss = new SimpleStruct();

            ss.gs.StringField = "field in GenericStruct";

            var  ss_arr = new SimpleStruct [] {};
            var  gs     = new GenericStruct <Math> ();
            Math m      = new Math();

            Console.WriteLine($"Using the struct: {ss.dt}, {ss.gs.StringField}, ss_arr: {ss_arr.Length}, gs: {gs.StringField}");
        }
示例#10
0
 public SimpleStruct(string str, int f, DateTimeKind kind)
 {
     str_member = $"{str}#SimpleStruct#str_member";
     dt         = new DateTime(2020 + f, 1 + f, 2 + f, 3 + f, 5 + f, 6 + f);
     gs         = new GenericStruct <DateTime> {
         StringField = $"{str}#SimpleStruct#gs#StringField",
         List        = new System.Collections.Generic.List <DateTime> {
             new DateTime(2010 + f, 2 + f, 3 + f, 10 + f, 2 + f, 3 + f)
         },
         Options = Options.Option1
     };
     Kind = kind;
 }
示例#11
0
        public void CreateInstanceWithGenericStructInstantiationDefaultConstructor()
        {
            ITypeInfo type = Reflector.Wrap(typeof(GenericStruct <int>));
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            slotValues.Add(type.GetFields(PublicInstance)[0], 2);
            slotValues.Add(type.GetProperties(PublicInstance)[0], 3);

            ObjectCreationSpec  spec     = new ObjectCreationSpec(type, slotValues, NullConverter.Instance);
            GenericStruct <int> instance = (GenericStruct <int>)spec.CreateInstance();

            Assert.AreEqual(0, instance.constructorParamValue);
            Assert.AreEqual(2, instance.fieldValue);
            Assert.AreEqual(3, instance.propertyValue);
        }
示例#12
0
    public class ValueTypesTest {     //Only append content to this class as the test suite depends on line info
        public static void MethodWithLocalStructs()
        {
            var ss_local = new SimpleStruct("set in MethodWithLocalStructs", 1, DateTimeKind.Utc);
            var gs_local = new GenericStruct <ValueTypesTest> {
                StringField = "gs_local#GenericStruct<ValueTypesTest>#StringField"
            };

            ValueTypesTest vt_local = new ValueTypesTest {
                StringField          = "string#0",
                SimpleStructField    = new SimpleStruct("SimpleStructField#string#0", 5, DateTimeKind.Local),
                SimpleStructProperty = new SimpleStruct("SimpleStructProperty#string#0", 2, DateTimeKind.Utc), DT = new DateTime(2020, 1, 2, 3, 4, 5), RGB = RGB.Blue
            };

            Console.WriteLine($"Using the struct: {ss_local.gs.StringField}, gs: {gs_local.StringField}, {vt_local.StringField}");
        }
示例#13
0
 public void Full()
 {
     var nulunk = new Nulunk("nulunk-integration-tests");
     var r = new Random();
     for (var x = 0; x < 1000; x++)
     {
         var uPerson = new GenericStruct() { DateTime = DateTime.Now, Name = "Q", Random = r.Next() };
         if (x % 2 == 0)
             nulunk.Store(uPerson);
         else
         {
             nulunk.Store(JsonConvert.SerializeObject(uPerson));
         }
     }
     var t = nulunk.FlushAsync();
     t.Wait();
 }
示例#14
0
        public static async Task <bool> MethodWithLocalStructsStaticAsync()
        {
            var ss_local = new SimpleStruct("set in MethodWithLocalStructsStaticAsync", 1, DateTimeKind.Utc);
            var gs_local = new GenericStruct <int> {
                StringField = "gs_local#GenericStruct<ValueTypesTest>#StringField",
                List        = new System.Collections.Generic.List <int> {
                    5, 3
                },
                Options = Options.Option2
            };

            var result = await ss_local.AsyncMethodWithStructArgs(gs_local);

            Console.WriteLine($"Using the struct: {ss_local.gs.StringField}, result: {result}");

            return(result);
        }
示例#15
0
文件: debugger-test.cs 项目: cpw/mono
    public static int ActionTSignatureTest()
    {
        Action <GenericStruct <int[]> > fn_action     = (_) => { };
        Action <GenericStruct <int[]> > fn_action_del = Math.DelegateTargetWithVoidReturn;
        Action fn_action_bare = () => {};
        Action <GenericStruct <int[]> > fn_action_null = null;
        var fn_action_arr = new Action <GenericStruct <int[]> >[] {
            (gs) => new GenericStruct <int[]>(),
            Math.DelegateTargetWithVoidReturn,
            null
        };

        var gs = new GenericStruct <int[]>();

        fn_action(gs);
        fn_action_del(gs);
        fn_action_arr[0](gs);
        fn_action_bare();
        OuterMethod();
        return(0);
    }
示例#16
0
 public static GenericStruct <T> StructTest <T> (GenericStruct <T> t)
 {
     return(t);
 }
示例#17
0
    // Use this for initialization
    void Start()
    {
        LuaEnv       luaenv       = new LuaEnv();
        HotfixCalc   calc         = new HotfixCalc();
        NoHotfixCalc ordinaryCalc = new NoHotfixCalc();

        //对比热更与不热更标签用时(毫秒),执行同样的一组循环
        int CALL_TIME = 100 * 1000 * 1000;
        var start     = System.DateTime.Now;

        for (int i = 0; i < CALL_TIME; i++)
        {
            calc.Add(2, 1);  //return a-b=1
        }
        var d1 = (System.DateTime.Now - start).TotalMilliseconds;

        Debug.Log("Hotfix using:" + d1);

        start = System.DateTime.Now;
        for (int i = 0; i < CALL_TIME; i++)
        {
            ordinaryCalc.Add(2, 1);
        }
        var d2 = (System.DateTime.Now - start).TotalMilliseconds;

        Debug.Log("No Hotfix using:" + d2);
        Debug.Log("drop:" + ((d1 - d2) / d1));
        Debug.Log("Before Fix: 2 + 1 = " + calc.Add(2, 1));                                                                     //热更变成减法了
        Debug.Log("Before Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = " + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3))); //向量减法
        luaenv.DoString(@"
            xlua.hotfix(CS.HotfixCalc, 'Add', function(self, a, b)
                return a + b
            end)
        ");
        Debug.Log("After Fix: 2 + 1 = " + calc.Add(2, 1));                                                                      //热更再变成加法
        Debug.Log("After Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = " + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3)));

        double num;
        string str = "hehe";
        int    ret = calc.TestOut(100, out num, ref str);

        Debug.Log("ret = " + ret + ", num = " + num + ", str = " + str); //返回值是100+3,num+=2,str被赋值wrong version
        //打印test out, self=这个类,打印传入的值
        luaenv.DoString(@"
            xlua.hotfix(CS.HotfixCalc, 'TestOut', function(self, a, c, go)
                    print('TestOut', self, a, c, go)
                    if go then error('test error') end
                    return a + 10 , a + 20, 'right version'
                end)
        ");
        str = "hehe";
        ret = calc.TestOut(100, out num, ref str);
        Debug.Log("ret = " + ret + ", num = " + num + ", str = " + str); //110 120 rightversion,第一个可以理解成C#只接受第一个返回值

        luaenv.DoString(@"
            xlua.hotfix(CS.HotfixCalc, {
                 Test1 = function(self)
                    print('Test1', self) --self不是实参,相当于this,但是可以指向表
                    return 1
                 end;
                 Test2 = function(self, a, b)  --out向外传参可以不写
                     print('Test1', self, a, b)
                     return a + 10, 1024, b
                 end;
                 Test3 = function(a)
                    print(a)
                    return 10
                 end;
                 Test4 = function(a)
                    print(a)
                 end;
                 Test5 = function(self, a, ...)
                    print('Test4', self, a, ...)
                 end
            })
        ");
        //泛型热更演示
        int    r1 = calc.Test1 <int>(); //无论什么类型都是返回1
        double r2 = calc.Test1 <double>();

        Debug.Log("r1:" + r1 + ",r2:" + r2);

        string ss = "heihei"; //ref必须初始化
        int    r3 = calc.Test2(r1, out r2, ref ss);

        Debug.Log("r1:" + r1 + ",r2:" + r2 + ",r3:" + r3 + ",ss:" + ss); //这里面return c#只能接受第一个参数,因为有out和ref所以,r2 r3能取到值

        r3 = HotfixCalc.Test3("test3");
        r3 = HotfixCalc.Test3(2);
        r3 = HotfixCalc.Test3(this);  //lua变成C#之后再执行,这里面就和C#脚本的this是一样的
        Debug.Log("r3:" + r3);
        HotfixCalc.Test4(this);
        HotfixCalc.Test4(2);
        calc.Test5(10, "a", "b", "c");
        calc.Test5(10, 1, 3, 5);

        Debug.Log("----------------------before------------------------");
        //Stateless比较适合无状态的类,有状态的话,你得通过反射去操作私有成员,也没法新增状态(field)。Stateless有个好处,可以运行的任意时刻执行替换。
        // Stateful的代价是会在类增加一个LuaTable类型的字段(中间层面增加,不会改源代码)。但这种方式是适用性更广,比如你不想要lua状态,可以在构造函数拦截那返回空。而且操作状态性能比反射操作C#私有变量要好,也可以随意新增任意的状态信息。缺点是,执行成员函数之前就new好的对象,接收到的状态会是空,所以需要重启,在一开始就执行替换。
        TestStateful(); //Stateful方式下你可以在Lua的构造函数返回一个table,然后后续成员函数调用会把这个table给传递过去。
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        luaenv.DoString(@"
            xlua.hotfix(CS.StatefullTest, {
                ['.ctor'] = function(csobj)  --构造函数固定写法
                    return {evt = {}, start = 0}
                end;
                set_AProp = function(self, v)
                    print('set_AProp', v)
                    self.AProp = v
                end;
                get_AProp = function(self)
                    return self.AProp
                end;
                get_Item = function(self, k)
                    print('get_Item', k)
                    return 1024
                end;
                set_Item = function(self, k, v)
                    print('set_Item', k, v)
                end;
                add_AEvent = function(self, cb)
                    print('add_AEvent', cb)
                    table.insert(self.evt, cb)
                end;
                remove_AEvent = function(self, cb)
                   print('remove_AEvent', cb)
                   for i, v in ipairs(self.evt) do
                       if v == cb then
                           table.remove(self.evt, i)
                           break
                       end
                   end
                end;
                Start = function(self)
                    print('Start')
                    for _, cb in ipairs(self.evt) do
                        cb(self.start, 2)
                    end
                    self.start = self.start + 1
                end;
                StaticFunc = function(a, b, c)
                   print(a, b, c)
                end;
                GenericTest = function(self, a)
                   print(self, a)
                end;
                Finalize = function(self)   --析构函数固定写法
                   print('Finalize', self)
                end
           })
        ");
        Debug.Log("----------------------after------------------------");
        TestStateful(); //在下面调用执行的
        luaenv.FullGc();
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();

        var genericObj = new GenericClass <double>(1.1);

        genericObj.Func1();
        Debug.Log(genericObj.Func2());
        //泛型类要指定类型后热更
        luaenv.DoString(@"
            xlua.hotfix(CS['GenericClass`1[System.Double]'], {  --数字代表几个参数,固定的泛型命名写法 Type.GetType Method (String)
                ['.ctor'] = function(obj, a)
                    print('GenericClass<double>', obj, a)
                end;
                Func1 = function(obj)
                    print('GenericClass<double>.Func1', obj)
                end;
                Func2 = function(obj)
                    print('GenericClass<double>.Func2', obj)
                    return 1314
                end
            })
        ");
        genericObj = new GenericClass <double>(1.1);
        genericObj.Func1();
        Debug.Log(genericObj.Func2());

        InnerTypeTest itt = new InnerTypeTest();

        itt.Foo();
        luaenv.DoString(@"
            xlua.hotfix(CS.InnerTypeTest, 'Bar', function(obj)
                    print('lua Bar', obj)
                    return {x = 10, y = 20}
                end)
        ");
        itt.Foo();

        StructTest st = new StructTest(gameObject);

        Debug.Log("go=" + st.GetGo(123, "john"));
        luaenv.DoString(@"
            xlua.hotfix(CS.StructTest, 'GetGo', function(self, a, b)
                    print('GetGo', self, a, b)
                    return nil
                end)
        ");
        Debug.Log("go=" + st.GetGo(123, "john"));

        GenericStruct <int> gs = new GenericStruct <int>(1);

        Debug.Log("gs.GetA()=" + gs.GetA(123));
        luaenv.DoString(@"
            xlua.hotfix(CS['GenericStruct`1[System.Int32]'], 'GetA', function(self, a)
                    print('GetA',self, a)
                    return 789
                end)
        ");
        Debug.Log("gs.GetA()=" + gs.GetA(123));

        try
        {
            calc.TestOut(100, out num, ref str, gameObject);
        }
        catch (LuaException e)
        {
            Debug.Log("throw in lua an catch in c# ok, e.Message:" + e.Message);
        }
    }
示例#18
0
    // Use this for initialization
    void Start()
    {
        LuaEnv       luaenv       = new LuaEnv();
        HotfixCalc   calc         = new HotfixCalc();
        NoHotfixCalc ordinaryCalc = new NoHotfixCalc();

        int CALL_TIME = 100 * 1000 * 1000;
        var start     = System.DateTime.Now;

        for (int i = 0; i < CALL_TIME; i++)
        {
            calc.Add(2, 1);
        }
        var d1 = (System.DateTime.Now - start).TotalMilliseconds;

        Debug.Log("Hotfix using:" + d1);

        start = System.DateTime.Now;
        for (int i = 0; i < CALL_TIME; i++)
        {
            ordinaryCalc.Add(2, 1);
        }
        var d2 = (System.DateTime.Now - start).TotalMilliseconds;

        Debug.Log("No Hotfix using:" + d2);

        Debug.Log("drop:" + ((d1 - d2) / d1));

        Debug.Log("Before Fix: 2 + 1 = " + calc.Add(2, 1));
        Debug.Log("Before Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = " + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3)));
        luaenv.DoString(@"
            xlua.hotfix(CS.HotfixCalc, 'Add', function(self, a, b)
                return a + b
            end)
        ");
        Debug.Log("After Fix: 2 + 1 = " + calc.Add(2, 1));
        Debug.Log("After Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = " + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3)));

        double num;
        string str = "hehe";
        int    ret = calc.TestOut(100, out num, ref str);

        Debug.Log("ret = " + ret + ", num = " + num + ", str = " + str);

        luaenv.DoString(@"
            xlua.hotfix(CS.HotfixCalc, 'TestOut', function(self, a, c, go)
                    print('TestOut', self, a, c, go)
                    if go then error('test error') end
                    return a + 10, a + 20, 'right version'
                end)
        ");
        str = "hehe";
        ret = calc.TestOut(100, out num, ref str);
        Debug.Log("ret = " + ret + ", num = " + num + ", str = " + str);

        luaenv.DoString(@"
            xlua.hotfix(CS.HotfixCalc, {
                 Test1 = function(self)
                    print('Test1', self)
                    return 1
                 end;
                 Test2 = function(self, a, b)
                     print('Test1', self, a, b)
                     return a + 10, 1024, b
                 end;
                 Test3 = function(a)
                    print(a)
                    return 10
                 end;
                 Test4 = function(a)
                    print(a)
                 end;
                 Test5 = function(self, a, ...)
                    print('Test4', self, a, ...)
                 end
            })
        ");

        int    r1 = calc.Test1 <int>();
        double r2 = calc.Test1 <double>();

        Debug.Log("r1:" + r1 + ",r2:" + r2);

        string ss = "heihei";
        int    r3 = calc.Test2(r1, out r2, ref ss);

        Debug.Log("r1:" + r1 + ",r2:" + r2 + ",r3:" + r3 + ",ss:" + ss);

        r3 = HotfixCalc.Test3("test3");
        r3 = HotfixCalc.Test3(2);
        r3 = HotfixCalc.Test3(this);
        Debug.Log("r3:" + r3);
        HotfixCalc.Test4(this);
        HotfixCalc.Test4(2);
        calc.Test5(10, "a", "b", "c");
        calc.Test5(10, 1, 3, 5);

        Debug.Log("----------------------before------------------------");
        TestStateful();
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        luaenv.DoString(@"
            xlua.hotfix(CS.StatefullTest, {
                ['.ctor'] = function(csobj)
                    return {evt = {}, start = 0}
                end;
                set_AProp = function(self, v)
                    print('set_AProp', v)
                    self.AProp = v
                end;
                get_AProp = function(self)
                    return self.AProp
                end;
                get_Item = function(self, k)
                    print('get_Item', k)
                    return 1024
                end;
                set_Item = function(self, k, v)
                    print('set_Item', k, v)
                end;
                add_AEvent = function(self, cb)
                    print('add_AEvent', cb)
                    table.insert(self.evt, cb)
                end;
                remove_AEvent = function(self, cb)
                   print('remove_AEvent', cb)
                   for i, v in ipairs(self.evt) do
                       if v == cb then
                           table.remove(self.evt, i)
                           break
                       end
                   end
                end;
                Start = function(self)
                    print('Start')
                    for _, cb in ipairs(self.evt) do
                        cb(self.start, 2)
                    end
                    self.start = self.start + 1
                end;
                StaticFunc = function(a, b, c)
                   print(a, b, c)
                end;
                GenericTest = function(self, a)
                   print(self, a)
                end;
                Finalize = function(self)
                   print('Finalize', self)
                end
           })
        ");
        Debug.Log("----------------------after------------------------");
        TestStateful();
        luaenv.FullGc();
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();

        var genericObj = new GenericClass <double>(1.1);

        genericObj.Func1();
        Debug.Log(genericObj.Func2());
        luaenv.DoString(@"
            xlua.hotfix(CS['GenericClass`1[System.Double]'], {
                ['.ctor'] = function(obj, a)
                    print('GenericClass<double>', obj, a)
                end;
                Func1 = function(obj)
                    print('GenericClass<double>.Func1', obj)
                end;
                Func2 = function(obj)
                    print('GenericClass<double>.Func2', obj)
                    return 1314
                end
            })
        ");
        genericObj = new GenericClass <double>(1.1);
        genericObj.Func1();
        Debug.Log(genericObj.Func2());

        InnerTypeTest itt = new InnerTypeTest();

        itt.Foo();
        luaenv.DoString(@"
            xlua.hotfix(CS.InnerTypeTest, 'Bar', function(obj)
                    print('lua Bar', obj)
                    return {x = 10, y = 20}
                end)
        ");
        itt.Foo();

        StructTest st = new StructTest(gameObject);

        Debug.Log("go=" + st.GetGo(123, "john"));
        luaenv.DoString(@"
            xlua.hotfix(CS.StructTest, 'GetGo', function(self, a, b)
                    print('GetGo', self, a, b)
                    return nil
                end)
        ");
        Debug.Log("go=" + st.GetGo(123, "john"));

        GenericStruct <int> gs = new GenericStruct <int>(1);

        Debug.Log("gs.GetA()=" + gs.GetA(123));
        luaenv.DoString(@"
            xlua.hotfix(CS['GenericStruct`1[System.Int32]'], 'GetA', function(self, a)
                    print('GetA',self, a)
                    return 789
                end)
        ");
        Debug.Log("gs.GetA()=" + gs.GetA(123));

        try
        {
            calc.TestOut(100, out num, ref str, gameObject);
        }
        catch (LuaException e)
        {
            Debug.Log("throw in lua an catch in c# ok, e.Message:" + e.Message);
        }
    }
示例#19
0
 public static GenericStruct <bool[]> DelegateTargetForSignatureTest(Math m, GenericStruct <GenericStruct <T[]> > gs) => new GenericStruct <bool[]>();
示例#20
0
 public static void DelegateTargetWithVoidReturn(GenericStruct <int[]> gs)
 {
 }
示例#21
0
 public static ValidationResult CorrectValidationMethodOneArgGenericStruct(GenericStruct <int> testStruct)
 {
     return(ValidationResult.Success);
 }
示例#22
0
    public void Execute()
    {
        var key = new GenericStruct();

        FFFF(key);
    }
示例#23
0
        public void SizeOf_GenericStruct_Value_Generic()
        {
            GenericStruct <int> value = default;

            Assert.Equal(8, Marshal.SizeOf(value));
        }
    public static int Main()
    {
        var a             = new ClassA();
        var b             = new ClassB();
        var c             = new ClassC();
        var gsInt         = new GenericStruct <int>();
        var gsString      = new GenericStruct <string>();
        var arrayOfUInt32 = new uint[100];
        var arrayOfInt32  = new int[100];
        var arrayOfString = new string[100];

        for (int i = 0; i < 200; i++)
        {
            AssertEquals(IsArray(arrayOfUInt32), true);
            AssertEquals(IsArray(arrayOfInt32), true);
            AssertEquals(IsArray(arrayOfString), false);
            AssertEquals(IsArray(a), false);
            AssertEquals(IsArray(b), false);
            AssertEquals(IsArray(c), false);
            AssertEquals(IsArray(gsInt), false);
            AssertEquals(IsArray(gsString), false);
            AssertEquals(IsArray(null), false);

            AssertEquals(IsClassA(arrayOfUInt32), false);
            AssertEquals(IsClassA(arrayOfInt32), false);
            AssertEquals(IsClassA(arrayOfString), false);
            AssertEquals(IsClassA(a), true);
            AssertEquals(IsClassA(b), false);
            AssertEquals(IsClassA(c), false);
            AssertEquals(IsClassA(gsInt), false);
            AssertEquals(IsClassA(gsString), false);
            AssertEquals(IsClassA(null), false);

            AssertEquals(IsGenericStruct <string>(arrayOfUInt32), false);
            AssertEquals(IsGenericStruct <string>(arrayOfInt32), false);
            AssertEquals(IsGenericStruct <string>(arrayOfString), false);
            AssertEquals(IsGenericStruct <string>(a), true);
            AssertEquals(IsGenericStruct <string>(b), false);
            AssertEquals(IsGenericStruct <string>(c), false);
            AssertEquals(IsGenericStruct <string>(gsInt), false);
            AssertEquals(IsGenericStruct <string>(gsString), false);
            AssertEquals(IsGenericStruct <int>(arrayOfUInt32), false);
            AssertEquals(IsGenericStruct <int>(arrayOfInt32), false);
            AssertEquals(IsGenericStruct <int>(arrayOfString), false);
            AssertEquals(IsGenericStruct <int>(a), true);
            AssertEquals(IsGenericStruct <int>(b), false);
            AssertEquals(IsGenericStruct <int>(c), false);
            AssertEquals(IsGenericStruct <int>(gsInt), false);
            AssertEquals(IsGenericStruct <int>(null), false);

            AssertEquals(IsGenericInterface <string>(arrayOfUInt32), false);
            AssertEquals(IsGenericInterface <string>(arrayOfInt32), false);
            AssertEquals(IsGenericInterface <string>(arrayOfString), false);
            AssertEquals(IsGenericInterface <string>(a), true);
            AssertEquals(IsGenericInterface <string>(b), false);
            AssertEquals(IsGenericInterface <string>(c), false);
            AssertEquals(IsGenericInterface <string>(gsInt), false);
            AssertEquals(IsGenericInterface <string>(gsString), false);
            AssertEquals(IsGenericInterface <int>(arrayOfUInt32), false);
            AssertEquals(IsGenericInterface <int>(arrayOfInt32), false);
            AssertEquals(IsGenericInterface <int>(arrayOfString), false);
            AssertEquals(IsGenericInterface <int>(a), true);
            AssertEquals(IsGenericInterface <int>(b), false);
            AssertEquals(IsGenericInterface <int>(c), false);
            AssertEquals(IsGenericInterface <int>(gsInt), false);
            AssertEquals(IsGenericInterface <int>(gsString), false);
            AssertEquals(IsGenericInterface <int>(null), false);

            AssertEquals(IsIInterface(arrayOfUInt32), false);
            AssertEquals(IsIInterface(arrayOfInt32), false);
            AssertEquals(IsIInterface(arrayOfString), false);
            AssertEquals(IsIInterface(a), true);
            AssertEquals(IsIInterface(b), false);
            AssertEquals(IsIInterface(c), false);
            AssertEquals(IsIInterface(gsInt), false);
            AssertEquals(IsIInterface(gsString), false);
            AssertEquals(IsIInterface(null), false);

            AssertThrows <InvalidCastException>(() => CastToClassA(gsInt));
            AssertThrows <InvalidCastException>(() => CastToClassA(gsString));
            AssertThrows <InvalidCastException>(() => CastToClassA(arrayOfUInt32));
            AssertThrows <InvalidCastException>(() => CastToClassA(arrayOfInt32));
            AssertThrows <InvalidCastException>(() => CastToClassA(arrayOfString));

            AssertThrows <InvalidCastException>(() => CastToArray(a));
            AssertThrows <InvalidCastException>(() => CastToArray(b));
            AssertThrows <InvalidCastException>(() => CastToArray(c));
            AssertThrows <InvalidCastException>(() => CastToArray(gsInt));
            AssertThrows <InvalidCastException>(() => CastToArray(gsString));

            AssertEquals(CastToIInterface(a), a);
            AssertEquals(CastToIInterface(b), b);
            AssertThrows <InvalidCastException>(() => CastToIInterface(c));
            AssertThrows <InvalidCastException>(() => CastToIInterface(gsInt));
            AssertThrows <InvalidCastException>(() => CastToIInterface(gsString));
            AssertThrows <InvalidCastException>(() => CastToIInterface(arrayOfUInt32));
            AssertThrows <InvalidCastException>(() => CastToIInterface(arrayOfInt32));
            AssertThrows <InvalidCastException>(() => CastToIInterface(arrayOfString));

            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(a));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(b));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(c));
            AssertEquals(CastToGenericInterface <int>(gsInt), gsInt);
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(gsString));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(arrayOfUInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(arrayOfInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <int>(arrayOfString));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(a));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(b));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(c));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(gsInt));
            AssertEquals(CastToGenericInterface <string>(gsString), gsString);
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(arrayOfUInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(arrayOfInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericInterface <string>(arrayOfString));

            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(a));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(b));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(c));
            AssertEquals(CastToGenericStruct <int>(gsInt), gsInt);
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(gsString));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(arrayOfUInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(arrayOfInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <int>(arrayOfString));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(a));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(b));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(c));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(gsInt));
            AssertEquals(CastToGenericStruct <string>(gsString), gsString);
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(arrayOfUInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(arrayOfInt32));
            AssertThrows <InvalidCastException>(() => CastToGenericStruct <string>(arrayOfString));
            AssertThrows <NullReferenceException>(() => CastToGenericStruct <string>(null));

            Thread.Sleep(20);
        }
        return(100);
    }
示例#25
0
    public void RemoveEventFromEventList(GenericStruct _event)
    {
        List <GenericStruct> newEventList = eventList.genericEventList.Where(x => x.GetID() != _event.GetID()).ToList();

        eventList.genericEventList = newEventList;
    }
示例#26
0
    public static int Main()
    {
        Console.WriteLine("Test creation/invocation of non-generic closed instance or open static delegates over various generic methods");

        GenericClass <EQStruct <long> >  refr = new GenericClass <EQStruct <long> >();
        GenericStruct <EQStruct <long> > val  = new GenericStruct <EQStruct <long> >();

        refr.value = 50;
        val.value  = 50;

        //Closed instance methods
        dc1 d1 = new dc1(refr.M1);

        d1(50);
        d1 = new dc1(val.M1);
        d1(50);

        dc4 d2 = new dc4(refr.M2);

        d2(new EQStruct <long>(50), 50);
        d2 = new dc4(val.M2);
        d2(new EQStruct <long>(50), 50);

        dc5 d3 = new dc5(refr.M3);

        d3(50, new EQStruct <long>(50));
        d3 = new dc5(val.M3);
        d3(50, new EQStruct <long>(50));

        dc4 d4 = new dc4(refr.M4);

        d4(new EQStruct <long>(50), 50);
        d4 = new dc4(val.M4);
        d4(new EQStruct <long>(50), 50);

        dc5 d5 = new dc5(refr.M5);

        d5(50, new EQStruct <long>(50));
        d5 = new dc5(val.M5);
        d5(50, new EQStruct <long>(50));

        dc6 d6 = new dc6(refr.M6);

        d6(new EQClass <long>(50), 50);
        d6 = new dc6(val.M6);
        d6(new EQClass <long>(50), 50);

        dc7 d7 = new dc7(refr.M7);

        d7(50, new EQClass <long>(50));
        d7 = new dc7(val.M7);
        d7(50, new EQClass <long>(50));

        dc6 d8 = new dc6(refr.M8 <EQClass <long> >);

        d8(new EQClass <long>(50), 50);
        d8 = new dc6(val.M8 <EQClass <long> >);
        d8(new EQClass <long>(50), 50);

        dc7 d9 = new dc7(refr.M9 <EQClass <long> >);

        d9(50, new EQClass <long>(50));
        d9 = new dc7(val.M9 <EQClass <long> >);
        d9(50, new EQClass <long>(50));

        //Open static methods
        d1 = new dc1(GenericClass <EQStruct <long> > .SM1);
        d1(50);
        d1 = new dc1(GenericStruct <EQStruct <long> > .SM1);
        d1(50);

        d2 = new dc4(GenericClass <EQStruct <long> > .SM2);
        d2(new EQStruct <long>(50), 50);
        d2 = new dc4(GenericStruct <EQStruct <long> > .SM2);
        d2(new EQStruct <long>(50), 50);

        d3 = new dc5(GenericClass <EQStruct <long> > .SM3);
        d3(50, new EQStruct <long>(50));
        d3 = new dc5(GenericStruct <EQStruct <long> > .SM3);
        d3(50, new EQStruct <long>(50));

        d4 = new dc4(GenericClass <EQStruct <long> > .SM4);
        d4(new EQStruct <long>(50), 50);
        d4 = new dc4(GenericStruct <EQStruct <long> > .SM4);
        d4(new EQStruct <long>(50), 50);

        d5 = new dc5(GenericClass <EQStruct <long> > .SM5);
        d5(50, new EQStruct <long>(50));
        d5 = new dc5(GenericStruct <EQStruct <long> > .SM5);
        d5(50, new EQStruct <long>(50));

        d6 = new dc6(GenericClass <EQStruct <long> > .SM6);
        d6(new EQClass <long>(50), 50);
        d6 = new dc6(GenericStruct <EQStruct <long> > .SM6);
        d6(new EQClass <long>(50), 50);

        d7 = new dc7(GenericClass <EQStruct <long> > .SM7);
        d7(50, new EQClass <long>(50));
        d7 = new dc7(GenericStruct <EQStruct <long> > .SM7);
        d7(50, new EQClass <long>(50));

        d8 = new dc6(GenericClass <EQStruct <long> > .SM8 <EQClass <long> >);
        d8(new EQClass <long>(50), 50);
        d8 = new dc6(GenericStruct <EQStruct <long> > .SM8 <EQClass <long> >);
        d8(new EQClass <long>(50), 50);

        d9 = new dc7(GenericClass <EQStruct <long> > .SM9 <EQClass <long> >);
        d9(50, new EQClass <long>(50));
        d9 = new dc7(GenericStruct <EQStruct <long> > .SM9 <EQClass <long> >);
        d9(50, new EQClass <long>(50));

        Console.WriteLine("Done - Passed");
        return(100);
    }
示例#27
0
 public void Add(GenericStruct generic)
 {
     mGenericStructs.Add(generic);
 }
示例#28
0
	public static int Main(){
		Console.WriteLine("Test creation/invocation of non-generic closed instance or open static delegates over various generic methods");

		GenericClass<EQStruct<long>> refr = new GenericClass<EQStruct<long>>();
		GenericStruct<EQStruct<long>> val = new GenericStruct<EQStruct<long>>();
		refr.value = 50;
		val.value = 50;

		//Closed instance methods
		dc1 d1 = new dc1(refr.M1);
		d1(50);
		d1 = new dc1(val.M1);
		d1(50);

		dc4 d2 = new dc4(refr.M2);
		d2(new EQStruct<long>(50),50);
		d2 = new dc4(val.M2);
		d2(new EQStruct<long>(50),50);

		dc5 d3 = new dc5(refr.M3);
		d3(50, new EQStruct<long>(50));
		d3 = new dc5(val.M3);
		d3(50, new EQStruct<long>(50));

		dc4 d4 = new dc4(refr.M4);
		d4(new EQStruct<long>(50),50);
		d4 = new dc4(val.M4);
		d4(new EQStruct<long>(50),50);

		dc5 d5 = new dc5(refr.M5);
		d5(50, new EQStruct<long>(50));
		d5 = new dc5(val.M5);
		d5(50, new EQStruct<long>(50));

		dc6 d6 = new dc6(refr.M6);
		d6(new EQClass<long>(50),50);
		d6 = new dc6(val.M6);
		d6(new EQClass<long>(50),50);

		dc7 d7 = new dc7(refr.M7);
		d7(50,new EQClass<long>(50));
		d7 = new dc7(val.M7);
		d7(50,new EQClass<long>(50));

		dc6 d8 = new dc6(refr.M8<EQClass<long>>);
		d8(new EQClass<long>(50),50);
		d8 = new dc6(val.M8<EQClass<long>>);
		d8(new EQClass<long>(50),50);

		dc7 d9 = new dc7(refr.M9<EQClass<long>>);
		d9(50,new EQClass<long>(50));
		d9 = new dc7(val.M9<EQClass<long>>);
		d9(50,new EQClass<long>(50));

		//Open static methods
		d1 = new dc1(GenericClass<EQStruct<long>>.SM1);
		d1(50);
		d1 = new dc1(GenericStruct<EQStruct<long>>.SM1);
		d1(50);

		d2 = new dc4(GenericClass<EQStruct<long>>.SM2);
		d2(new EQStruct<long>(50),50);
		d2 = new dc4(GenericStruct<EQStruct<long>>.SM2);
		d2(new EQStruct<long>(50),50);

		d3 = new dc5(GenericClass<EQStruct<long>>.SM3);
		d3(50, new EQStruct<long>(50));
		d3 = new dc5(GenericStruct<EQStruct<long>>.SM3);
		d3(50, new EQStruct<long>(50));

		d4 = new dc4(GenericClass<EQStruct<long>>.SM4);
		d4(new EQStruct<long>(50),50);
		d4 = new dc4(GenericStruct<EQStruct<long>>.SM4);
		d4(new EQStruct<long>(50),50);

		d5 = new dc5(GenericClass<EQStruct<long>>.SM5);
		d5(50, new EQStruct<long>(50));
		d5 = new dc5(GenericStruct<EQStruct<long>>.SM5);
		d5(50, new EQStruct<long>(50));

		d6 = new dc6(GenericClass<EQStruct<long>>.SM6);
		d6(new EQClass<long>(50),50);
		d6 = new dc6(GenericStruct<EQStruct<long>>.SM6);
		d6(new EQClass<long>(50),50);

		d7 = new dc7(GenericClass<EQStruct<long>>.SM7);
		d7(50,new EQClass<long>(50));
		d7 = new dc7(GenericStruct<EQStruct<long>>.SM7);
		d7(50,new EQClass<long>(50));

		d8 = new dc6(GenericClass<EQStruct<long>>.SM8<EQClass<long>>);
		d8(new EQClass<long>(50),50);
		d8 = new dc6(GenericStruct<EQStruct<long>>.SM8<EQClass<long>>);
		d8(new EQClass<long>(50),50);

		d9 = new dc7(GenericClass<EQStruct<long>>.SM9<EQClass<long>>);
		d9(50,new EQClass<long>(50));
		d9 = new dc7(GenericStruct<EQStruct<long>>.SM9<EQClass<long>>);
		d9(50,new EQClass<long>(50));		

		Console.WriteLine("Done - Passed");
		return 100;
	}