2020-09-18 18:38:11 +10:00
|
|
|
|
using System.Collections;
|
2020-09-09 19:15:47 +10:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-19 00:14:04 +10:00
|
|
|
|
using System;
|
2020-09-09 19:15:47 +10:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Explorer.Tests
|
|
|
|
|
{
|
|
|
|
|
public class TestClass
|
|
|
|
|
{
|
|
|
|
|
public static TestClass Instance => m_instance ?? (m_instance = new TestClass());
|
|
|
|
|
private static TestClass m_instance;
|
|
|
|
|
|
2020-09-11 00:17:13 +10:00
|
|
|
|
public TestClass()
|
|
|
|
|
{
|
|
|
|
|
ILHashSetTest = new Il2CppSystem.Collections.Generic.HashSet<string>();
|
|
|
|
|
ILHashSetTest.Add("1");
|
|
|
|
|
ILHashSetTest.Add("2");
|
|
|
|
|
ILHashSetTest.Add("3");
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 20:03:57 +10:00
|
|
|
|
public static int StaticProperty => 5;
|
|
|
|
|
public static int StaticField = 5;
|
|
|
|
|
public int NonStaticField;
|
|
|
|
|
|
2020-09-18 18:03:17 +10:00
|
|
|
|
public static string TestGeneric<C, T>(string arg0) where C : Component
|
|
|
|
|
{
|
2020-09-19 00:14:04 +10:00
|
|
|
|
return $"C: '{typeof(C).FullName}', T: '{typeof(T).FullName}', arg0: '{arg0}'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2)
|
|
|
|
|
{
|
|
|
|
|
arg2 = "this is arg2";
|
|
|
|
|
|
|
|
|
|
return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
|
2020-09-18 18:03:17 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//// this type of generic is not supported, due to requiring a non-primitive argument.
|
|
|
|
|
//public static T TestDifferentGeneric<T>(T obj) where T : Component
|
|
|
|
|
//{
|
|
|
|
|
// return obj;
|
|
|
|
|
//}
|
|
|
|
|
|
2020-09-15 17:38:10 +10:00
|
|
|
|
// test a non-generic dictionary
|
|
|
|
|
|
|
|
|
|
public Hashtable TestNonGenericDict()
|
|
|
|
|
{
|
|
|
|
|
return new Hashtable
|
|
|
|
|
{
|
|
|
|
|
{ "One", 1 },
|
|
|
|
|
{ "Two", 2 },
|
|
|
|
|
{ "Three", 3 },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IL2CPP HASHTABLE NOT SUPPORTED! Cannot assign Il2CppSystem.Object from primitive struct / string.
|
|
|
|
|
// Technically they are "supported" but if they contain System types they will not work.
|
|
|
|
|
|
|
|
|
|
//public Il2CppSystem.Collections.Hashtable TestIl2CppNonGenericDict()
|
|
|
|
|
//{
|
|
|
|
|
// var table = new Il2CppSystem.Collections.Hashtable();
|
|
|
|
|
// table.Add("One", 1);
|
|
|
|
|
// table.Add("One", 2);
|
|
|
|
|
// table.Add("One", 3);
|
|
|
|
|
// return table;
|
|
|
|
|
//}
|
|
|
|
|
|
2020-09-11 00:17:13 +10:00
|
|
|
|
// test HashSets
|
|
|
|
|
|
|
|
|
|
public static HashSet<string> HashSetTest = new HashSet<string>
|
|
|
|
|
{
|
|
|
|
|
"One",
|
|
|
|
|
"Two",
|
|
|
|
|
"Three"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static Il2CppSystem.Collections.Generic.HashSet<string> ILHashSetTest;
|
|
|
|
|
|
2020-09-10 18:02:41 +10:00
|
|
|
|
// Test indexed parameter
|
2020-09-09 19:15:47 +10:00
|
|
|
|
|
|
|
|
|
public string this[int arg0, string arg1]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return $"arg0: {arg0}, arg1: {arg1}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-10 18:02:41 +10:00
|
|
|
|
// Test basic list
|
|
|
|
|
|
2020-09-09 19:15:47 +10:00
|
|
|
|
public static List<string> TestList = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"1",
|
|
|
|
|
"2",
|
|
|
|
|
"3",
|
|
|
|
|
"etc..."
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-10 18:02:41 +10:00
|
|
|
|
// Test a nested dictionary
|
|
|
|
|
|
|
|
|
|
public static Dictionary<int, Dictionary<string, int>> NestedDictionary = new Dictionary<int, Dictionary<string, int>>
|
2020-09-09 19:15:47 +10:00
|
|
|
|
{
|
|
|
|
|
{
|
2020-09-10 18:02:41 +10:00
|
|
|
|
1,
|
|
|
|
|
new Dictionary<string, int>
|
2020-09-09 19:15:47 +10:00
|
|
|
|
{
|
2020-09-10 18:02:41 +10:00
|
|
|
|
{
|
|
|
|
|
"Sub 1", 123
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"Sub 2", 456
|
|
|
|
|
},
|
2020-09-09 19:15:47 +10:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-09-10 18:02:41 +10:00
|
|
|
|
2,
|
|
|
|
|
new Dictionary<string, int>
|
2020-09-09 19:15:47 +10:00
|
|
|
|
{
|
2020-09-10 18:02:41 +10:00
|
|
|
|
{
|
|
|
|
|
"Sub 3", 789
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"Sub 4", 000
|
|
|
|
|
},
|
2020-09-09 19:15:47 +10:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-10 18:02:41 +10:00
|
|
|
|
// Test a basic method
|
|
|
|
|
|
2020-09-09 19:15:47 +10:00
|
|
|
|
public static Color TestMethod(float r, float g, float b, float a)
|
|
|
|
|
{
|
|
|
|
|
return new Color(r, g, b, a);
|
|
|
|
|
}
|
2020-09-10 18:02:41 +10:00
|
|
|
|
|
|
|
|
|
// A method with default arguments
|
|
|
|
|
|
|
|
|
|
public static Vector3 TestDefaultArgs(float arg0, float arg1, float arg2 = 5.0f)
|
|
|
|
|
{
|
|
|
|
|
return new Vector3(arg0, arg1, arg2);
|
|
|
|
|
}
|
2020-09-09 19:15:47 +10:00
|
|
|
|
}
|
|
|
|
|
}
|