void AddAutoBindings(ModelNode parent, ModelNode child) { var components = ComponentsProperty(parent); if (components != null && child.DataType.IsCompatibleWith(GetActualPropertyType(components))) { parent.AddBinding(components, child); return; } var serailizationChildren = SerializationChildProperties(parent); foreach (var p in serailizationChildren) { if (child.DataType.IsCompatibleWith(GetActualPropertyType(p))) { parent.AddBinding(p, child); return; } } var primary = PrimaryProperty(parent); if (primary != null && child.DataType.IsCompatibleWith(GetActualPropertyType(primary))) { parent.AddBinding(primary, child); } }
ModelNode Convert(ModelNode parent, XElement elm) { var dt = GetDataType(elm); if (dt == null) { throw Error(elm, "Data type '" + elm.Name.LocalName + "' could not be resolved"); } var name = GetUXAttribute(elm, "Name", (string)null); var className = GetUXAttribute(elm, "ClassName", (string)null); var genMember = GetUXAttribute(elm, "Member", GenerateMemberMode.None); var autoBind = GetUXAttribute(elm, "AutoBind", true); var bindingString = GetUXAttribute(elm, "Binding", ""); var bindings = (string[])null; if (bindingString.Length > 0) { bindings = bindingString.Split(','); } var node = new ModelNode(dt, name, genMember, className, autoBind); // Process explicit bindings if (parent == null) { Error(elm, "Illegal 'Binding': element has no parent"); } else { if (bindings != null) { foreach (var b in bindings) { var ps = FindPropertyOrStyleProperty(elm, parent.DataType, b); parent.AddBinding(ps, node); } } } // Process implicit bindings if (parent != null && autoBind) { AddAutoBindings(parent, node); } foreach (var attr in elm.Attributes()) { if (IsUXNamespaceAttribute(attr)) { continue; } var prop = attr.Name.LocalName; var ps = FindPropertyOrStyleProperty(attr, node.DataType, prop); if (ps is Property) { var value = Parse(attr, attr.Value, (ps as Property).DataType); if (value != null) { node.PropertyValues[ps as Property] = value; } } else if (ps is Field) { var styleProp = ps as Field; var value = Parse(attr, attr.Value, styleProp.DataType.GenericTypeArguments[1]); if (value != null) { node.PropertyValues[styleProp] = value; } } } foreach (var child in elm.Elements()) { if (IsUXNamespaceElement(child)) { } else { node.Children.Add(Convert(node, child)); } } return(node); }