static Action <NullFreeDictionary <string, object> > GetAction(string originalName, string newName) { return(nfd => { if (nfd == null) { throw new InvalidMigrationSource("NullFreeDictionary cannot be null"); } if (!nfd.ContainsKey(originalName)) { throw new MissingProperty($"{originalName ?? "[NULL]"} does not exist"); } if (newName == null) { throw new NullPropertyName("New property name cannot be null"); } if (nfd.ContainsKey(newName)) { throw new DuplicateProperty($"{newName ?? "[NULL]"} already exists"); } if (!PropertyNameValidator.IsValid(newName)) { throw new InvalidPropertyName($"New name '{newName ?? "[NULL]"}' is not a valid property name"); } var existingValue = nfd[originalName]; nfd.Remove(originalName); nfd.Add(newName, existingValue); }); }
static Action <NullFreeDictionary <string, object> > GetAction(string originalName, string newName) { return(nfd => { if (nfd == null) { throw new MigrationSourceCannotBeNull(originalName); } if (newName == null) { throw new PropertyNameInTargetIsNull(originalName); } if (!nfd.ContainsKey(originalName)) { throw new MissingProperty(originalName ?? "[NULL]"); } if (nfd.ContainsKey(newName)) { throw new DuplicateProperty(newName ?? "[NULL]"); } if (!PropertyNameValidator.IsValid(newName)) { throw new InvalidPropertyName(newName ?? "[NULL]"); } var existingValue = nfd[originalName]; nfd.Remove(originalName); nfd.Add(newName, existingValue); }); }
static Action <NullFreeDictionary <string, object> > GetAction(string name, T value) { return(nfd => { if (nfd == null) { throw new InvalidMigrationSource("NullFreeDictionary cannot be null"); } if (value == null) { return; } if (name == null) { throw new NullPropertyName("Cannot add a property with the name NULL"); } if (!PropertyNameValidator.IsValid(name)) { throw new InvalidPropertyName($"Property {name ?? "[NULL]" } is not a valid identifier"); } if (nfd.ContainsKey(name)) { throw new DuplicateProperty($"Property {name ?? "[NULL]" } already exists on this target"); } nfd.Add(name, typeof(T).GetPropertyBagObjectValue(value)); }); }
static Action <NullFreeDictionary <string, object> > GetAction(string name, T value) { return(nfd => { if (nfd == null) { throw new MigrationSourceCannotBeNull(name); } if (value == null) { return; } if (name == null) { throw new PropertyNameIsNull(); } if (!PropertyNameValidator.IsValid(name)) { throw new InvalidPropertyName(name ?? "[NULL]"); } if (nfd.ContainsKey(name)) { throw new DuplicateProperty(name ?? "[NULL]"); } nfd.Add(name, typeof(T).GetPropertyBagObjectValue(value)); }); }