Created
May 20, 2015 06:10
-
-
Save trapezoid/eafc720159e5bfa351ba to your computer and use it in GitHub Desktop.
IL2CPP Issue
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 System; | |
using System.Runtime.InteropServices; | |
using System.Diagnostics; | |
namespace GenericTest | |
{ | |
public interface IReadable | |
{ | |
void Read(); | |
int GetValue { get; } | |
} | |
public struct InterfacedStruct : IReadable | |
{ | |
public int Value; | |
public int GetValue { get { return Value; } } | |
#region IReadable implementation | |
public void Read () | |
{ | |
this.Value = 1; | |
} | |
#endregion | |
} | |
public class GenericTest<T> where T : struct, IReadable | |
{ | |
public void Do(Action<T> callback) | |
{ | |
var s = new T (); | |
s.Read (); | |
callback (s); | |
} | |
public void DoWithoutNew(T s, Action<T> callback) | |
{ | |
s.Read (); | |
callback (s); | |
} | |
} | |
public static class GenericTestCase | |
{ | |
public static void Do(Action<InterfacedStruct> callback) | |
{ | |
var s = new InterfacedStruct (); | |
s.Read (); | |
callback (s); | |
} | |
public static void DoWithoutNew(InterfacedStruct s, Action<InterfacedStruct> callback) | |
{ | |
s.Read (); | |
callback (s); | |
} | |
public static void DoInterfaceWithoutNew(IReadable s, Action<IReadable> callback) | |
{ | |
s.Read (); | |
callback (s); | |
} | |
public static void TestInterface() | |
{ | |
UnityEngine.Debug.Log ("InterfacedStruct"); | |
IReadable readable = new InterfacedStruct (); | |
DoInterfaceWithoutNew(readable, s => UnityEngine.Debug.Log("Value is " + s.GetValue.ToString())); | |
} | |
public static void TestGeneric() | |
{ | |
UnityEngine.Debug.Log ("Generic + InterfacedStruct + new"); | |
var tester = new GenericTest<InterfacedStruct> (); | |
tester.Do(s => UnityEngine.Debug.Log("Value is " + s.Value.ToString())); | |
} | |
public static void TestGenericWithoutNew() | |
{ | |
UnityEngine.Debug.Log ("Generic + InterfacedStruct"); | |
var tester = new GenericTest<InterfacedStruct> (); | |
tester.DoWithoutNew(new InterfacedStruct(), s => UnityEngine.Debug.Log("Value is " + s.Value.ToString())); | |
} | |
public static void TestNonGeneric() | |
{ | |
UnityEngine.Debug.Log ("Struct + new"); | |
Do(s => UnityEngine.Debug.Log("Value is " + s.Value.ToString())); | |
} | |
public static void TestNonGenericWithoutNew() | |
{ | |
UnityEngine.Debug.Log ("Struct"); | |
DoWithoutNew(new InterfacedStruct(), s => UnityEngine.Debug.Log("Value is " + s.Value.ToString())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment