Last active
May 3, 2018 13:52
-
-
Save lauromoura/dd7bd97f0fc815b6f8e1070d7d520282 to your computer and use it in GitHub Desktop.
Changes on the container traits after C# rename
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
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs | |
index 173f54d..b5e523f 100644 | |
--- a/src/bindings/mono/eina_mono/eina_container_common.cs | |
+++ b/src/bindings/mono/eina_mono/eina_container_common.cs | |
@@ -1,6 +1,7 @@ | |
#pragma warning disable 1591 | |
using System; | |
+using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Collections.Generic; | |
@@ -522,19 +523,47 @@ public static class TraitFunctions | |
private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>(); | |
+ private static System.Type AsEflConcreteType(System.Type type) | |
+ { | |
+ if (!IsEflObject(type)) | |
+ return null; | |
+ | |
+ if (type.IsInterface) | |
+ { | |
+ string[] names = type.FullName.Split('.'); | |
+ names[names.Count() - 1] = names.Last().Substring(1); // Remove the leading 'I' (What about user-defined interfaces?) | |
+ | |
+ string fullName = string.Join(".", names); | |
+ return type.Assembly.GetType(fullName); // That was our best guess... | |
+ } | |
+ | |
+ | |
+ System.Type current = type; | |
+ while (current != null) | |
+ { | |
+ if (current.Name.EndsWith("Inherit")) | |
+ break; | |
+ current = current.BaseType; | |
+ } | |
+ | |
+ if (current.Name.EndsWith("Inherit")) | |
+ { | |
+ string fullName = current.FullName.Substring(0, current.FullName.LastIndexOf("Inherit")); | |
+ return type.Assembly.GetType(fullName); | |
+ } | |
+ | |
+ return type; // Not inherited neither interface, so it should be a concrete. | |
+ } | |
+ | |
public static object RegisterTypeTraits<T>() | |
{ | |
object traits; | |
var type = typeof(T); | |
if (IsEflObject(type)) | |
{ | |
- System.Type concrete = type; | |
- if (!type.Name.EndsWith("Concrete")) | |
- { | |
- var c = type.Assembly.GetType(type.FullName + "Concrete"); | |
- if (c != null && type.IsAssignableFrom(c)) | |
- concrete = c; | |
- } | |
+ System.Type concrete = AsEflConcreteType(type); | |
+ if (concrete == null) | |
+ throw new Exception("Failed to get a suitable concrete class for this type."); | |
traits = new EflObjectElementTraits<T>(concrete); | |
} | |
else if (IsString(type)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment