public void GetPropertyByFullName_should_include_classes_marked_with_Extender_compound_name()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Alpha));
            var fac = def.GetProperty("Charlie.ValueExtender", "https://ns.example.com/", GetPropertyOptions.IncludeExtenders);

            AssertIsCharlieValueExtender(fac);
        }
Beispiel #2
0
        public void add_method_default_implicit()
        {
            PropertyTreeDefinition def = PropertyTreeDefinition.FromType(typeof(S));

            Assert.Equal(2, def.Operators.Count);
            Assert.True(def.Operators.Contains("something"));
        }
        public void GetPropertyByLocalName_should_include_classes_marked_with_Extender()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Alpha));
            var fac = def.GetProperty("ValueExtender", GetPropertyOptions.IncludeExtenders);

            AssertIsCharlieValueExtender(fac);
        }
        public void add_child_operators_inherited()
        {
            var def = PropertyTreeDefinition.FromType(typeof(ContainerControl));
            var fac = def.GetOperator("p");

            Assert.NotNull(fac);
        }
        public void get_property_nominal()
        {
            var a = PropertyTreeDefinition.FromType(typeof(Alpha));

            Assert.Contains("A", a.Properties.Select(t => t.Name));
            Assert.NotNull(a.GetProperty("A"));
        }
        public void Properties_should_include_the_IProperties_indexer()
        {
            var def     = PropertyTreeDefinition.FromType(typeof(Properties));
            var indexer = def.Properties.OfType <IndexerUsingIPropertiesPropertyDefinition>().FirstOrDefault();

            Assert.NotNull(indexer);
        }
        void IRoleAttribute.ProcessExtensionMethod(MethodInfo mi)
        {
            var target = (ReflectedPropertyTreeDefinition)PropertyTreeDefinition.FromType(
                mi.GetParameters()[0].ParameterType);

            target.AddFactoryDefinition(ReflectedPropertyTreeFactoryDefinition.FromFactory(this, mi));
        }
        public void generic_list_operators_should_override()
        {
            var def = PropertyTreeDefinition.FromType(typeof(GenericList));

            Assert.Null(def.GetOperator("add"));
            Assert.NotNull(def.GetOperator("s"));
        }
Beispiel #9
0
        public void addon_method_nominal()
        {
            var def        = PropertyTreeDefinition.FromType(typeof(Omicron));
            var alphaAddon = def.GetOperator("alpha");

            Assert.NotNull(alphaAddon);
            Assert.Equal(0, alphaAddon.Parameters.Count);
        }
Beispiel #10
0
        public void addon_method_extension()
        {
            var def        = PropertyTreeDefinition.FromType(typeof(Omicron));
            var gammaAddon = def.GetOperator("gammaOptional");

            Assert.NotNull(gammaAddon);
            Assert.Equal(2, gammaAddon.Parameters.Count);
        }
Beispiel #11
0
        public void ComputeName_Natural_should_use_return_type(Type type, string expected)
        {
            var    method = type.GetTypeInfo().GetMethod("AddNew");
            string name   = ((IRoleAttribute)AddAttribute.Natural).ComputeName(method);

            Assert.Equal(expected, name, StringComparer.OrdinalIgnoreCase);
            Assert.Contains(expected, PropertyTreeDefinition.FromType(type).EnumerateOperators().Select(t => t.Name));
        }
        public void simple_properties_should_equal_expected_values_in_simple_types()
        {
            var a = PropertyTreeDefinition.FromType(typeof(Alpha));

            Assert.Equal("Alpha", a.Name);
            Assert.Equal("https://ns.example.com/", a.Namespace);
            Assert.Equal(typeof(Alpha), a.SourceClrType);
        }
        public void Name_should_equal_mangle_in_constructed_generic_type()
        {
            var a = PropertyTreeDefinition.FromType(typeof(List <Alpha>));

            Assert.Equal("List-1", a.Name);
            Assert.Equal("", a.Namespace);
            Assert.Equal(typeof(List <Alpha>), a.SourceClrType);
        }
        public void add_child_operators_inherited_constructed_generics()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Collection <Control>));
            var fac = def.GetOperator("add");

            Assert.NotNull(fac);
            Assert.Equal("", fac.Namespace);
            Assert.Equal("Add", fac.Name);
        }
        public void properties_should_include_text_type_indexer()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Dictionary <QualifiedName, int>));

            Assert.NotNull(def.Properties.FirstOrDefault(t => t.IsIndexer));

            def = PropertyTreeDefinition.FromType(typeof(Dictionary <string, int>));
            Assert.NotNull(def.Properties.FirstOrDefault(t => t.IsIndexer));
        }
        public void add_child_operators_nominal()
        {
            var def  = PropertyTreeDefinition.FromType(typeof(IAddChild <Control>));
            var fac  = def.GetOperator("p");
            var fac2 = def.Operators.GetByLocalName("p");

            Assert.NotNull(fac);
            Assert.NotEmpty(fac2);
        }
Beispiel #17
0
        public PropertyDefinition FindProperty(PropertyTreeDefinition definition,
                                               Type componentType,
                                               QualifiedName qn,
                                               IEnumerable <PropertyTreeDefinition> ancestors)
        {
            // Allow any namespace contained in the definition base classes
            var result = definition
                         .EnumerateProperties()
                         .FirstOrDefault(t => Compare(t, qn, definition));

            if (result != null)
            {
                return(result);
            }

            int dot = qn.LocalName.IndexOf('.');

            if (dot > 0)
            {
                // TODO Index whether the PTD has extenders so we can skip some ancestors (perf)
                string prefix = qn.LocalName.Substring(0, dot);

                foreach (var currentDef in ancestors)
                {
                    if (currentDef.Name == prefix)
                    {
                        // TODO Local name could be different
                        var prop = currentDef.GetProperty(qn);
                        if (prop != null)
                        {
                            return(prop);
                        }
                    }
                }
            }
            else
            {
                foreach (var curDefinition in ancestors)
                {
                    var prop = curDefinition.GetProperty(qn);
                    if (IsValidExtender(prop, componentType))
                    {
                        return(prop);
                    }

                    var qn2 = qn.ChangeLocalName(curDefinition.Name + "." + qn.LocalName);
                    prop = curDefinition.GetProperty(qn2);
                    if (IsValidExtender(prop, componentType))
                    {
                        return(prop);
                    }
                }
            }

            return(null);
        }
        public void get_extender_property_nominal()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Canvas));
            var fac = def.GetProperty("Canvas.top");

            Assert.NotNull(fac);
            Assert.True(fac.IsExtender);
            Assert.True(fac.CanExtend(typeof(Control)));
            Assert.Equal("https://ns.example.com/", fac.Namespace);
        }
        public void get_extender_property_extension_method_inherit()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Paragraph));
            var fac = def.GetProperty("left", GetPropertyOptions.IncludeExtenders);

            Assert.NotNull(fac);
            Assert.True(fac.IsExtender);
            Assert.True(fac.CanExtend(typeof(Paragraph)));
            Assert.Equal("https://ns.example.com/", fac.Namespace);
        }
        public void FindOperator_should_implicitly_handle_inherited_operator_names()
        {
            var unit = new PropertyNameLookupHelper();
            var comp = PropertyTreeDefinition.FromType(typeof(ComponentCollection));

            // Though add is defined inside default NS, it is accessible via the NS of the type
            var qn     = QualifiedName.Create(comp.Namespace, "add");
            var result = unit.FindOperator(comp, typeof(ComponentCollection), qn);

            Assert.NotNull(result);
        }
        public void get_generic_list_operators()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Delta));

            Assert.Equal(0, def.Operators.Count);

            def = PropertyTreeDefinition.FromType(typeof(IList <Alpha>));
            Assert.NotNull(def.GetOperator("add"));
            Assert.NotNull(def.GetOperator("remove"));
            Assert.NotNull(def.GetOperator("clear"));
        }
        internal virtual OperatorDefinition SelectOperator(QualifiedName qn)
        {
            var treeDef = PropertyTreeDefinition.FromType(this.ComponentType);
            var factory = propertyLookup.FindOperator(treeDef, this.ComponentType, qn);

            if (factory == null && ProbeRuntimeComponents())
            {
                factory = propertyLookup.FindOperator(treeDef, this.ComponentType, qn);
            }
            return(factory);
        }
Beispiel #23
0
        public void Bind_should_prefer_reflection()
        {
            var props = PropertyTreeDefinition.FromType(typeof(F))
                        .Properties.GetByLocalName("s");
            var def = PropertyTreeDefinition.FromType(typeof(F));

            const string text = @"<fileTarget s='50'> </fileTarget>";
            var          f    = StreamContext.FromText(text).ReadPropertyTree <F>();

            Assert.Equal(50, f.S);
        }
Beispiel #24
0
        public void SetProperty_should_apply_to_IPropertiesContainer()
        {
            var def     = PropertyTreeDefinition.FromType(typeof(IPropertiesContainer));
            var indexer = def.Properties.OfType <IndexerUsingIPropertiesPropertyDefinition>().FirstOrDefault();

            Assert.NotNull(indexer);

            var it = new FakePropertiesContainer();

            indexer.SetValue(it, QualifiedName.Parse("a"), "hello");

            Assert.Equal("hello", it.Properties["a"]);
        }
        public void FindOperator_should_implicitly_handle_inherited_operator_names_constructed_generics()
        {
            var unit = new PropertyNameLookupHelper();
            var comp = PropertyTreeDefinition.FromType(typeof(Collection <Control>));

            // Though add is defined inside default NS, it is accessible via the NS of the type
            var qn     = QualifiedName.Create("https://ns.example.com", "add");
            var result = unit.FindOperator(comp, typeof(Collection <Control>), qn);

            var ops = comp.EnumerateOperators();

            Assert.NotNull(result);
            Assert.Same(comp.GetOperator("add"), result);
        }
Beispiel #26
0
 internal override void ApplyUriContextToProperties(Uri baseUri)
 {
     if (Component != null)
     {
         foreach (var prop in PropertyTreeDefinition.FromType(ComponentType).UriContextCache)
         {
             object value;
             if (prop.TryGetValue(Component, null, prop.QualifiedName, out value) && value != null)
             {
                 ((IUriContext)value).BaseUri = baseUri;
             }
         }
     }
 }
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator self, NodeList children)
            {
                QualifiedName name = self.QualifiedName;
                var           ctor = PropertyTreeDefinition.FromType(target.ComponentType).Constructor;

                if (target.ShouldConstruct && ctor != null)
                {
                    OperatorDefinition op = ctor;
                    var args = parent.ExtractParameterDictionary(op, target, parent.GetBasicServices(self), children);

                    target = target.BindConstructor(ctor, args);
                }

                return(target);
            }
        public void get_extender_property_extension_method()
        {
            var def = PropertyTreeDefinition.FromType(typeof(Control));
            var fac = def.GetProperty("ControlExtensions.left");

            Assert.NotNull(fac);
            Assert.True(fac.IsExtender);
            Assert.True(fac.CanExtend(typeof(Paragraph)));
            Assert.Equal("https://ns.example.com/", fac.Namespace);

            // Look for type inheritance
            def = PropertyTreeDefinition.FromType(typeof(Paragraph));
            var other = def.GetProperty("ControlExtensions.left");

            Assert.Same(fac, other);
        }
        void IRoleAttribute.ProcessExtensionMethod(MethodInfo mi)
        {
            var target = (ReflectedPropertyTreeDefinition)PropertyTreeDefinition.FromType(
                mi.GetParameters()[0].ParameterType);

            var attachedID = GetAttachedPropertyID(mi);
            var existing   = (ReflectedExtenderPropertyDefinition)target.GetProperty(attachedID);

            if (existing == null)
            {
                var extender = new ReflectedExtenderPropertyDefinition(attachedID);
                target.AddPropertyDefinition(extender);
                existing = extender;
            }

            existing.AddMethod(mi);
        }
        public PropertyDefinition FindProperty(PropertyTreeDefinition definition,
                                               Type componentType,
                                               QualifiedName qn,
                                               IEnumerable<PropertyTreeDefinition> ancestors)
        {
            // Allow any namespace contained in the definition base classes
            var result = definition
                .EnumerateProperties()
                .FirstOrDefault(t => Compare(t, qn, definition));

            if (result != null)
                return result;

            int dot = qn.LocalName.IndexOf('.');
            if (dot > 0) {
                // TODO Index whether the PTD has extenders so we can skip some ancestors (perf)
                string prefix = qn.LocalName.Substring(0, dot);

                foreach (var currentDef in ancestors) {
                    if (currentDef.Name == prefix) {
                        // TODO Local name could be different
                        var prop = currentDef.GetProperty(qn);
                        if (prop != null) {
                            return prop;
                        }
                    }
                }

            } else {

                foreach (var curDefinition in ancestors) {
                    var prop = curDefinition.GetProperty(qn);
                    if (IsValidExtender(prop, componentType))
                        return prop;

                    var qn2 = qn.ChangeLocalName(curDefinition.Name + "." + qn.LocalName);
                    prop = curDefinition.GetProperty(qn2);
                    if (IsValidExtender(prop, componentType))
                        return prop;

                }
            }

            return null;
        }
        internal PropertyTreeDefinition GetDefinition()
        {
            object component = this.Component;

            if (component != null)
            {
                return(PropertyTreeDefinition.FromValue(component));
            }

            else if (this.ComponentType != null)
            {
                return(PropertyTreeDefinition.FromType(this.ComponentType));
            }

            else
            {
                return(null);
            }
        }
 protected internal virtual void VisitPropertyTree(PropertyTreeDefinition node)
 {
     DefaultVisit(node);
 }
        private static bool Compare(PropertyNodeDefinition t,
                                    QualifiedName qn,
                                    PropertyTreeDefinition definition)
        {
            var x = t.QualifiedName;
            var y = qn;
            if (x == y)
                return true;

            if (string.Equals(x.LocalName, y.LocalName, StringComparison.OrdinalIgnoreCase))
                return x.Namespace == y.Namespace
                    || x.Namespace == string.Empty
                    || (definition.GetSerializationCandidateNamespaces().Any(m => m == y.Namespace));
            else
                return false;
        }
 public OperatorDefinition FindOperator(PropertyTreeDefinition definition, Type type, QualifiedName qn)
 {
     return definition
         .EnumerateOperators()
         .FirstOrDefault(t => Compare(t, qn, definition));
 }
 public PropertyTreeDefinition ImportType(PropertyTreeDefinition definition)
 {
     if (definition == null)
         throw new ArgumentNullException("definition");
     throw new NotImplementedException();
 }