Created
April 21, 2015 13:07
-
-
Save sailro/8b7e39620fa397e94d11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
using System.Linq; | |
public class Test : MonoBehaviour { | |
string testCecilSpec; | |
int[,] dynArray; | |
int[][][] dynJaggedArray; | |
static T CreateJaggedArray<T>(params int[] lengths) { | |
return (T)CreateJaggedArray(typeof(T).GetElementType(), 0, lengths); | |
} | |
static object CreateJaggedArray(Type type, int index, int[] lengths) { | |
var array = Array.CreateInstance(type, lengths[index]); | |
var elementType = type.GetElementType(); | |
if (elementType != null) | |
for (int i = 0; i < lengths[index]; i++) | |
array.SetValue(CreateJaggedArray(elementType, index + 1, lengths), i); | |
return array; | |
} | |
unsafe void Start() { | |
// Test Cecil specs with GenericTypeInstance(Of ArrayType( Of GenericTypeInstance(Of int) ) ) | |
Predicate<Nullable<int>[]> foo = t => t.Length == 3 && t[0] == 6 && !t[1].HasValue && t[2] == 1; | |
testCecilSpec = foo(new int?[]{6, null, 1}).ToString(); | |
// Test pointers | |
fixed (char* s = testCecilSpec) | |
{ | |
short* p = (short*)s; | |
*(p++) = (short)'X'; | |
*(p++) = (short)'Y'; | |
} | |
// Test dynamic arrays with lower bounds | |
dynArray = (int[,])Array.CreateInstance(typeof(int), new int[] { 4, 2 }, new int[] { -4, -1 }); | |
dynArray[-2, -1] = 666; | |
// Test dynamic jagged array | |
dynJaggedArray = CreateJaggedArray<int[][][]>(1, 2, 3); | |
dynJaggedArray[0][1][2] = 999; | |
} | |
void OnGUI () { | |
var str = testCecilSpec + dynArray[-2, -1] + dynJaggedArray[0][1][2]; | |
GUI.Label(new Rect(0, 0, 128, 32), str); // XYue666999 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment