public void Can_assign_value_to_private_property_in_base() { var obj = new B(); ReflectionHelpers.AssignPropertyValue(obj, "Foo2", "Fred"); Assert.AreEqual("Fred", obj.Foo2); }
public void Can_assign_value_to_public_property() { var obj = new B(); ReflectionHelpers.AssignPropertyValue(obj, "Bar", "Fred"); Assert.AreEqual("Fred", obj.Bar); }
private void AssignChildren(IDom source, T obj, TargetChildMapping mapping, CodeFirstMetadata parent) { foreach (var childMap in mapping.Children) { var newItems = ReflectionHelpers.InvokeGenericMethod(thisType, "CreateChildren", childMap.UnderlyingTypInfo, this, source, childMap, parent); ReflectionHelpers.AssignPropertyValue(obj, childMap.TargetName, newItems); } }
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); } } }