diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-12-21 16:01:28 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-12-21 16:01:28 +0100 |
| commit | e93697acd920c593e82dd232f0e6f28d434d9e49 (patch) | |
| tree | ac286523bb8ca7cc4bf259ad9d996a6caa8008ab /src/IML | |
| parent | c382841870f704e28b473d73b7fbc9e57a4f678a (diff) | |
Named node resolution, code clean and debug
modifié : Crow.csproj
modifié : src/IML/BindingDefinition.cs
modifié : src/IML/Context.cs
modifié : src/Instantiator.cs
modifié : src/ItemTemplate.cs
Diffstat (limited to 'src/IML')
| -rw-r--r-- | src/IML/BindingDefinition.cs | 3 | ||||
| -rw-r--r-- | src/IML/Context.cs | 45 |
2 files changed, 42 insertions, 6 deletions
diff --git a/src/IML/BindingDefinition.cs b/src/IML/BindingDefinition.cs index e357fcac..19a54d09 100644 --- a/src/IML/BindingDefinition.cs +++ b/src/IML/BindingDefinition.cs @@ -50,6 +50,9 @@ namespace Crow.IML } #endregion + public bool IsDataSourceBinding { get { return TargetNA == null; }} + public bool HasUnresolvedTargetName { get { return !string.IsNullOrEmpty(TargetName); }} + /// <summary> /// replace the target node address with corresponding named node address, and clear the target name once resolved /// </summary> diff --git a/src/IML/Context.cs b/src/IML/Context.cs index 09329e1b..104633c6 100644 --- a/src/IML/Context.cs +++ b/src/IML/Context.cs @@ -48,10 +48,8 @@ namespace Crow.IML 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 List<BindingDefinition> UnresolvedTargets = new List<BindingDefinition>(); + public Context (Type rootType) { RootType = rootType; @@ -86,10 +84,45 @@ namespace Crow.IML nodeBindings [origMember].Add (new MemberAddress (destNA, destMember)); } public void StorePropertyBinding(BindingDefinition bindDef){ + if (bindDef.HasUnresolvedTargetName) { + UnresolvedTargets.Add (bindDef); + return; + } StorePropertyBinding (bindDef.TargetNA, bindDef.TargetMember, bindDef.SourceNA, bindDef.SourceMember); - if (bindDef.TwoWay) - StorePropertyBinding (bindDef.SourceNA, bindDef.SourceMember, bindDef.TargetNA, bindDef.TargetMember); +// if (bindDef.TwoWay) +// StorePropertyBinding (bindDef.SourceNA, bindDef.SourceMember, bindDef.TargetNA, bindDef.TargetMember); } + public void StoreCurrentName(string name){ + if (!Names.ContainsKey(name)) + Names[name] = new List<NodeAddress>(); + Names[name].Add(CurrentNodeAddress); + } + public void ResolveNames (){ + foreach (BindingDefinition bd in UnresolvedTargets) { + if (!Names.ContainsKey (bd.TargetName)) + throw new Exception ("Target Name '" + bd.TargetName + "' not found"); + NodeAddress resolvedNA = null; + foreach (NodeAddress na in Names[bd.TargetName]) { + bool naMatch = true; + for (int i = 0; i < bd.TargetNA.Count; i++) { + if (bd.TargetNA [i] != na [i]) { + naMatch = false; + break; + } + } + if (naMatch) { + resolvedNA = na; + break; + } + } + if (resolvedNA == null) + throw new Exception ("Target Name '" + bd.TargetName + "' not found"); + + bd.ResolveTargetName (resolvedNA); + StorePropertyBinding (bd); + } + } + void initILGen () { il.DeclareLocal (typeof (GraphicObject)); |