public object?GetValue(string propertyName, bool throwWhenMissing = false) { PropertyDetail?info; if (PropertyDetails.TryGetValue(propertyName, out info)) { return(info.GetValue(this)); } else { if (UnidentifiedProperties is not null) { object?value; if (UnidentifiedProperties.TryGetValue(propertyName, out value)) { return(value); } } } if (throwWhenMissing) { throw new KeyNotFoundException(string.Format("A property with name '{0}' does not exist.", propertyName)); } return(null); }
public virtual void MapFrom(IReadOnlyDictionary <string, object?> properties) { bool hasUnidentifiedProperties = (Wrapper.GetEntity().InheritedUnidentifiedProperties() is not null); if (hasUnidentifiedProperties) { if (UnidentifiedProperties is null) { UnidentifiedProperties = new UnidentifiedPropertyCollection(Wrapper); } else { UnidentifiedProperties.ClearInternal(); } } foreach (KeyValuePair <string, object?> property in properties) { PropertyDetail?info; if (PropertyDetails.TryGetValue(property.Key, out info)) { info.SetValue(this, property.Value); } else if (UnidentifiedProperties is not null) { UnidentifiedProperties.AddInternal(property.Key, property.Value); } } }
public virtual IDictionary <string, object?> MapTo() { IDictionary <string, object?> dictionary = new Dictionary <string, object?>(); foreach (PropertyDetail info in PropertyDetails.Values) { object?value = info.GetValue(this); if (value is not null) { dictionary.Add(info.PropertyName, info.GetValue(this)); } } if (UnidentifiedProperties is not null) { UnidentifiedProperties.ForEachInternal(item => dictionary.Add(item)); } return(dictionary); }