Example #1
0
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator self, NodeList children)
            {
                Predicate <PropertyTreeNavigator> predicate = ImplicitDirective(target, "id");

                var node = children.FindAndRemove(predicate).FirstOrDefault();

                if (node == null)
                {
                    node = children.FindAndRemove("name").FirstOrDefault();
                }
                if (node != null)
                {
                    // TODO Handle when a name is duplicated or contains whitespace
                    var    ns = parent.FindNameScope(target);
                    string id = Convert.ToString(node.Value);

                    if (string.IsNullOrEmpty(id))
                    {
                        parent._errors.IdCannotBeBlank(node.FileLocation);
                    }
                    else if (ns.FindName(id) == null)
                    {
                        ns.RegisterName(id, target.Component);
                    }
                    else
                    {
                        parent._errors.IdAlreadyRegistered(id, node.FileLocation);
                    }

                    var nameProperty = target.SelectProperty(NamespaceUri.Default + "name");
                    if (nameProperty != null)
                    {
                        parent.DoPropertyBind(target, node, nameProperty);
                    }
                }

                return(target);
            }
            bool IApplyMemberStep.Apply(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator node)
            {
                PropertyDefinition prop = null;

                if (_allowDefault)
                {
                    var defaultProperties = target.GetDefinition().DefaultProperties;

                    if (defaultProperties.Skip(1).Any())
                    {
                        prop = defaultProperties.FirstOrDefault(p => p.TryGetValue(target.Component, node.QualifiedName));
                    }

                    if (prop == null)
                    {
                        prop = defaultProperties.FirstOrDefault();
                    }

                    if (prop == null)
                    {
                        return(false);
                    }
                }
                else
                {
                    var im = ImpliedName(node, target);
                    prop = target.SelectProperty(im);
                    if (prop == null || prop.IsIndexer)
                    {
                        return(false);
                    }
                }

                parent.DoPropertyBind(target, node, prop);
                return(true);
            }