public object this[string propertyName] { get { return(this.GetItem(propertyName).Value); } set { DbPropertyValues dbPropertyValues = value as DbPropertyValues; if (dbPropertyValues != null) { value = (object)dbPropertyValues.InternalPropertyValues; } IPropertyValuesItem propertyValuesItem = this.GetItem(propertyName); InternalPropertyValues internalPropertyValues = propertyValuesItem.Value as InternalPropertyValues; if (internalPropertyValues == null) { this.SetValue(propertyValuesItem, value); } else { InternalPropertyValues values = value as InternalPropertyValues; if (values == null) { throw Error.DbPropertyValues_AttemptToSetNonValuesOnComplexProperty(); } internalPropertyValues.SetValues(values); } } }
public void SetValues(object value) { IDictionary <string, Func <object, object> > propertyGetters = DbHelpers.GetPropertyGetters(value.GetType()); foreach (string propertyName in (IEnumerable <string>) this.PropertyNames) { Func <object, object> func; if (propertyGetters.TryGetValue(propertyName, out func)) { object newValue = func(value); IPropertyValuesItem propertyValuesItem = this.GetItem(propertyName); if (newValue == null && propertyValuesItem.IsComplex) { throw Error.DbPropertyValues_ComplexObjectCannotBeNull((object)propertyName, (object)this._type.Name); } InternalPropertyValues internalPropertyValues = propertyValuesItem.Value as InternalPropertyValues; if (internalPropertyValues == null) { this.SetValue(propertyValuesItem, newValue); } else { internalPropertyValues.SetValues(newValue); } } } }
private void SetPropertyValueUsingValues(InternalPropertyValues internalValues, object value) { InternalPropertyValues internalValue = internalValues[this.Name] as InternalPropertyValues; if (internalValue != null) { if (!internalValue.ObjectType.IsAssignableFrom(value.GetType())) { throw Error.DbPropertyValues_AttemptToSetValuesFromWrongObject((object)value.GetType().Name, (object)internalValue.ObjectType.Name); } internalValue.SetValues(value); } else { internalValues[this.Name] = value; } }