aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/IML/Node.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-11-22 11:01:58 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-11-22 11:01:58 +0100
commit19fd0792d6b89a8fbe39cf5069f0dd02fa548b64 (patch)
treeba483e320d1a2a9a8f58920e61f717a21ffa441d /src/IML/Node.cs
parent4fb8b3a075bd8232be6fdcbb1f5a3b45265d33b4 (diff)
graphic tree bindings valuechanges implementation
Diffstat (limited to 'src/IML/Node.cs')
-rw-r--r--src/IML/Node.cs45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/IML/Node.cs b/src/IML/Node.cs
index 9bc8f82a..a503a3bb 100644
--- a/src/IML/Node.cs
+++ b/src/IML/Node.cs
@@ -20,6 +20,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Reflection;
+using System.Reflection.Emit;
+using System.Collections.Generic;
namespace Crow.IML
{
@@ -43,24 +45,19 @@ namespace Crow.IML
#region Equality Compare
public override bool Equals (object obj)
{
- return obj is Node && this == (Node)obj;
+ if (obj == null)
+ return false;
+ Node n = (Node)obj;
+ return CrowType == n.CrowType && Index == n.Index;
}
public override int GetHashCode ()
{
return CrowType.GetHashCode () ^ Index.GetHashCode ();
}
- public static bool operator == (Node x, Node y)
- {
- return x.CrowType == y.CrowType && x.Index == y.Index;
- }
- public static bool operator != (Node x, Node y)
- {
- return !(x == y);
- }
#endregion
- public bool IsTemplate {
- get { return typeof (TemplatedControl).IsAssignableFrom (CrowType) && Index == 0; }
+ public bool HasTemplate {
+ get { return typeof (TemplatedControl).IsAssignableFrom (CrowType);}
}
public MethodInfo AddMethod {
get {
@@ -69,14 +66,36 @@ namespace Crow.IML
if (typeof (Container).IsAssignableFrom (CrowType))
return CompilerServices.miSetChild;
if (typeof (TemplatedContainer).IsAssignableFrom (CrowType))
- return Index == 0 ? CompilerServices.miLoadTmp : CompilerServices.miSetContent;
+ return Index < 0 ? CompilerServices.miLoadTmp : CompilerServices.miSetContent;
if (typeof (TemplatedGroup).IsAssignableFrom (CrowType))
- return Index == 0 ? CompilerServices.miLoadTmp : CompilerServices.miAddItem;
+ return Index < 0 ? CompilerServices.miLoadTmp : CompilerServices.miAddItem;
if (typeof (TemplatedControl).IsAssignableFrom (CrowType))
return CompilerServices.miLoadTmp;
return null;
}
}
+ public void EmitGetInstance (ILGenerator il){
+ if (typeof (Group).IsAssignableFrom (CrowType)) {
+ il.Emit (OpCodes.Ldfld, typeof(Group).GetField ("children", BindingFlags.Instance | BindingFlags.NonPublic));
+ il.Emit(OpCodes.Ldc_I4, Index);
+ il.Emit (OpCodes.Callvirt, typeof(List<GraphicObject>).GetMethod("get_Item", new Type[] { typeof(Int32) }));
+ return;
+ }
+ if (typeof(Container).IsAssignableFrom (CrowType) || Index < 0) {
+ il.Emit (OpCodes.Ldfld, typeof(PrivateContainer).GetField ("child", BindingFlags.Instance | BindingFlags.NonPublic));
+ return;
+ }
+ if (typeof(TemplatedContainer).IsAssignableFrom (CrowType)) {
+ il.Emit (OpCodes.Callvirt, typeof(TemplatedContainer).GetProperty ("Content").GetGetMethod ());
+ return;
+ }
+ if (typeof(TemplatedGroup).IsAssignableFrom (CrowType)) {
+ il.Emit (OpCodes.Callvirt, typeof(TemplatedGroup).GetProperty ("Items").GetGetMethod ());
+ il.Emit(OpCodes.Ldc_I4, Index);
+ il.Emit (OpCodes.Callvirt, typeof(List<GraphicObject>).GetMethod("get_Item", new Type[] { typeof(Int32) }));
+ return;
+ }
+ }
public static implicit operator string (Node sn)
{