aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/IML
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
parent4fb8b3a075bd8232be6fdcbb1f5a3b45265d33b4 (diff)
graphic tree bindings valuechanges implementation
Diffstat (limited to 'src/IML')
-rw-r--r--src/IML/Context.cs12
-rw-r--r--src/IML/MemberAddress.cs3
-rw-r--r--src/IML/Node.cs45
-rw-r--r--src/IML/NodeAddress.cs26
4 files changed, 57 insertions, 29 deletions
diff --git a/src/IML/Context.cs b/src/IML/Context.cs
index 44a9018b..e5d33374 100644
--- a/src/IML/Context.cs
+++ b/src/IML/Context.cs
@@ -44,13 +44,15 @@ namespace Crow.IML
//public SubNodeType curSubNodeType;
public Stack<Node> nodesStack = new Stack<Node> ();
- public Dictionary<string, string> Names = new Dictionary<string, string> ();
+ public Dictionary<string, List<NodeAddress>> Names = new Dictionary<string, List<NodeAddress>>();
public Dictionary<string, Dictionary<string, MemberAddress>> PropertyBindings = new Dictionary<string, Dictionary<string, MemberAddress>> ();
- public Dictionary<NodeAddress, Dictionary<string, MemberAddress>> Bindings =
- new Dictionary<NodeAddress, Dictionary<string, MemberAddress>>();
- public List<DataSourceBinding> DataSourceBindings = new List<DataSourceBinding>();
-
+ public Dictionary<NodeAddress, Dictionary<string, List<MemberAddress>>> Bindings =
+ new Dictionary<NodeAddress, Dictionary<string, List<MemberAddress>>>();
+ //public List<DataSourceBinding> DataSourceBindings = new List<DataSourceBinding>();
+ public Dictionary<NamedNodeAddress, Dictionary<string, MemberAddress>> NamedBindings =
+ new Dictionary<NamedNodeAddress, Dictionary<string, MemberAddress>>();
+
public Context (Type rootType)
{
RootType = rootType;
diff --git a/src/IML/MemberAddress.cs b/src/IML/MemberAddress.cs
index 89a293c3..7f3c93da 100644
--- a/src/IML/MemberAddress.cs
+++ b/src/IML/MemberAddress.cs
@@ -30,9 +30,10 @@ namespace Crow.IML
public struct MemberAddress
{
string memberName;
- MemberInfo member;
+ public MemberInfo member;
public NodeAddress Address;
+ public PropertyInfo Property { get { return member as PropertyInfo; }}
// public string Name {
// get { return memberName; }
// set { memberName = value; }
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)
{
diff --git a/src/IML/NodeAddress.cs b/src/IML/NodeAddress.cs
index 12ecec38..b7517b1f 100644
--- a/src/IML/NodeAddress.cs
+++ b/src/IML/NodeAddress.cs
@@ -28,9 +28,16 @@ namespace Crow.IML
{
public NodeAddress (Node[] nodes) : base(nodes) {
}
+
+ public Type NodeType { get { return this[this.Count -1].CrowType; }}
+
public override bool Equals (object obj)
{
- return obj is NodeAddress && this == obj as NodeAddress;
+ if (obj == null)
+ return false;
+
+ NodeAddress na = (NodeAddress)obj;
+ return this.SequenceEqual (na);
}
public override int GetHashCode ()
{
@@ -41,21 +48,20 @@ namespace Crow.IML
return hash;
}
}
- public static bool operator == (NodeAddress x, NodeAddress y)
- {
- return x.SequenceEqual (y);
- }
- public static bool operator != (NodeAddress x, NodeAddress y)
- {
- return !(x == y);
- }
public override string ToString ()
{
string tmp = "";
foreach (Node n in this)
- tmp += string.Format ("{0}[{1}];", n.CrowType.Name, n.Index);
+ tmp += string.Format ("{0};", n.Index);
return tmp;
}
}
+
+ public class NamedNodeAddress : NodeAddress {
+ public string Name;
+ public NamedNodeAddress(string name, Node[] nodes) : base(nodes){
+ Name = name;
+ }
+ }
}