|
@@ -1,6 +1,6 @@
|
|
|
namespace Invercargill {
|
|
|
|
|
|
- public delegate TProp PropertyGetter<TClass, TProp>(TClass object);
|
|
|
+ public delegate TProp PropertyGetter<TClass, TProp>(TClass object) throws Error;
|
|
|
public delegate bool PropertyPredicate<TClass>(TClass object);
|
|
|
public delegate void PropertySetter<TClass, TProp>(TClass object, TProp value) throws Error;
|
|
|
public delegate void PropertyDefaultSetter<TClass>(TClass object);
|
|
@@ -34,11 +34,15 @@ namespace Invercargill {
|
|
|
continue;
|
|
|
}
|
|
|
if(mapping.undefined_setter == null && !exists){
|
|
|
- throw new IndexError.KEY_NOT_FOUND(@"Failed to map into $(typeof(T).name()): Mandatory property \"$(mapping.name)\" was not present in the properties list");
|
|
|
+ throw new IndexError.KEY_NOT_FOUND(@"Failed to map into $(typeof(T).name()): Property \"$(mapping.name)\" does not have an undefined setter and no matching property was found");
|
|
|
}
|
|
|
var element = properties[mapping.name];
|
|
|
- if(element.is_null()) {
|
|
|
-
|
|
|
+ if(mapping.null_setter != null && element.is_null()) {
|
|
|
+ mapping.null_setter(object);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(mapping.null_setter == null && element.is_null()) {
|
|
|
+ throw new ElementError.INVALID_CONVERSION(@"Failed to map into $(typeof(T).name()): Property \"$(mapping.name)\" does not have a null setter and a null value was found");
|
|
|
}
|
|
|
mapping.setter(object, properties[mapping.name]);
|
|
|
}
|
|
@@ -50,7 +54,7 @@ namespace Invercargill {
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
- public override Properties map_from(T object) {
|
|
|
+ public override Properties map_from(T object) throws Error {
|
|
|
var properties = new PropertiesDictionary();
|
|
|
foreach (var mapping in mappings) {
|
|
|
// Check undefined
|
|
@@ -144,7 +148,7 @@ namespace Invercargill {
|
|
|
public virtual PropertyMappingBuilder<T> map_many_with<TNative, TElement>(string name, owned PropertyGetter<T, Enumerable<TNative>> getter, owned PropertySetter<T, Enumerable<TNative>> setter, Mapper<TNative, TElement> mapper) {
|
|
|
var mapping = new PropertyMapping<T>() {
|
|
|
name = name,
|
|
|
- getter = (o) => new NativeElement<Elements>(getter(o).select<TElement>(i => mapper.map_from(i)).to_elements()),
|
|
|
+ getter = (o) => new NativeElement<Elements>(getter(o).try_select<TElement>(i => mapper.map_from(i)).to_elements()),
|
|
|
setter = (o,d) => {
|
|
|
var collection = new Series<TNative>();
|
|
|
foreach (var properties in d.as<Elements>().elements_as<TElement>()) {
|