public View Inflate(string name) { if (!name.EndsWith(FileExtension)) { name += FileExtension; } var path = Path.Combine(config.Paths.Layouts, name); var typesBinder = new MappedTypesBinder { KnownTypes = ViewHelper.GetViewTypes() }; var content = File.ReadAllText(path); var view = JsonConvert.DeserializeObject <View>(content, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, Binder = typesBinder, Converters = new JsonConverter[] { new DimensionConverter(resources), new ColourConverter(resources), new StringConverter(resources), new IntegerConverter(resources) } }); return(view); }
public void LoadValues() { var typesBinder = new MappedTypesBinder { KnownTypes = { { "String", typeof(StringResource) }, { "Integer", typeof(IntegerResource) }, { "Dimension", typeof(DimensionResource) }, { "Colour", typeof(ColourResource) } } }; foreach (var file in ValueFiles) { var path = Path.Combine(config.Paths.Values, file); log.Verbose(Tag, "Deserialising '{0}'", path); var content = File.ReadAllText(path); var values = JsonConvert.DeserializeObject <Dictionary <string, IValueResource> >(content, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, Binder = typesBinder, Converters = new JsonConverter[] { new DimensionConverter(this), new ColourConverter(this), new StringConverter(this), new IntegerConverter(this) } }); values.ForEach(p => { var key = p.Key; var resource = p.Value; if (resource is DimensionResource) { if (Dimensions.ContainsKey(key)) { throw new DuplicateValueNameException("Dimension", key); } Dimensions.Add(key, (resource as DimensionResource).Value); } else if (resource is IntegerResource) { if (Integers.ContainsKey(key)) { throw new DuplicateValueNameException("Integer", key); } Integers.Add(key, (resource as IntegerResource).Value); } else if (resource is StringResource) { if (Strings.ContainsKey(key)) { throw new DuplicateValueNameException("String", key); } Strings.Add(key, (resource as StringResource).Value); } else if (resource is ColourResource) { if (Colours.ContainsKey(key)) { throw new DuplicateValueNameException("Colour", key); } Colours.Add(key, (resource as ColourResource).Value); } }); } }