Exemple #1
0
        public void Can_determine_if_property_can_be_written()
        {
            var obj = new A();

            Assert.IsFalse(ReflectionUtilities.CanSetProperty(obj, "Foo"));
            Assert.IsTrue(ReflectionUtilities.CanSetProperty(obj, "Bar"));
            Assert.IsTrue(ReflectionUtilities.CanSetProperty(obj, "FooBar"));
            Assert.IsFalse(ReflectionUtilities.CanSetProperty(obj, "FooBarX"));
        }
        private void AssignAttributesToProperties(IHasAttributes source, T obj, TargetChildMapping mapping)
        {
            var usage = MakeValuePairList(source);

            foreach (var map in mapping.Attributes)
            {
                var valueUsage = usage.Where(x => x.Value.Key == map.TargetName).FirstOrDefault();
                if (valueUsage != null)
                {
                    if (ReflectionUtilities.CanSetProperty(obj, map.TargetName))
                    {
                        valueUsage.IncrementUse();
                        ReflectionHelpers.AssignPropertyValue(obj, map.TargetName, valueUsage.Value.Value);
                    }
                }
            }
        }
        private void AssignNamedProperties(IDom source, T obj, TargetChildMapping mapping)
        {
            var sourceHasStructuredDocs = source as IHasStructuredDocumentation;

            if (sourceHasStructuredDocs != null)
            {
                var xmlDocs = sourceHasStructuredDocs.StructuredDocumentation;
                obj.XmlCommentString = xmlDocs.Document;
            }
            var namedProperties = mapping.GetNamedProperties().ToList();

            foreach (var namedProperty in namedProperties)
            {
                var value = source.RequestValue(namedProperty, true);
                //while (value == null) { value = source.Parent.RequestValue(namedProperty); }
                if (ReflectionUtilities.CanSetProperty(obj, namedProperty))
                {
                    ReflectionHelpers.AssignPropertyValue(obj, namedProperty, value);
                }
            }
        }
Exemple #4
0
 public void CanSetProperty_throws_on_null()
 {
     Assert.AreEqual("", ReflectionUtilities.CanSetProperty(null, "Bar"));
 }