public static void SetValue(IDictionary <string, object> child, OverrideDetails details, string root) { var path = details.Attribute.Path; var pathParts = path.Split(Consts.PathSeperator); var obj = child; var containingType = details.Property.PropertyType; foreach (var pathPart in pathParts.Take(pathParts.Count() - 1)) { containingType = GetPropertyType(containingType, pathPart, details); obj = obj[pathPart] as IDictionary <string, object>; if (obj == null) { throw new ProgrammerErrorException("We managed to find the type via reflection, but our " + "object holding the data is formed to match."); } } var targetPropertyName = pathParts.Last(); var targetPropertyType = GetPropertyType(containingType, targetPropertyName, details); obj[targetPropertyName] = ValueDeserialiser.GetValue(details.Attribute.Value, targetPropertyType, $"{root}.{path}", $"setting override from property '{details.Property.Name}' in " + $"type '{details.ContainingType}'"); var sourcePath = root.Substring(root.IndexOf('.') + 1); // Trim the top root obj[targetPropertyName + Consts.SourceMetadata] = $"Override on {sourcePath}"; }
private static Type GetPropertyType(Type containingType, string propertyName, OverrideDetails details) { var property = GetProperties(containingType).SingleOrDefault(p => p.Name == propertyName); if (property == null) { throw new InvalidPropertySpecifierException(containingType, propertyName, details); } return(property.PropertyType); }
internal InvalidPropertySpecifierException(Type containingType, string propertyName, OverrideDetails details) : this(containingType, propertyName, details.Attribute.Path, details.Property, details.ContainingType) { }