public static void ClearValue(OneToOneAssociation property, NakedObject target) { object valueHolder = property.get(target).getObject(); MethodInfo m = valueHolder.GetType().GetMethod("clear"); m.Invoke(valueHolder, new object[] {}); }
public static void SetValue <T>(OneToOneAssociation property, NakedObject target, Naked proposed) { object valueHolder = property.get(target).getObject(); MethodInfo m = valueHolder.GetType().GetMethod("setValue", new[] { typeof(T) }); m.Invoke(valueHolder, new[] { proposed.getObject() }); }
private void SetAssociation(OneToOneAssociation property, NakedObject target, Naked proposed) { if (proposed is NakedObject) { property.setAssociation(target, (NakedObject)proposed); } else { MethodInfo m = GetType().GetMethod("SetValue").MakeGenericMethod(proposed.getObject().GetType()); m.Invoke(null, new object[] { property, target, proposed }); } }
private static Consent IsAssociationValid(OneToOneAssociation property, NakedObject target, Naked proposed, bool allowDisabled = false) { if (allowDisabled && property.isAvailable(target).isVetoed()) { return(new Allow()); } if (proposed is NakedObject) { return(property.isAssociationValid(target, (NakedObject)proposed)); } return(property.isValueValid(target, (NakedValue)proposed)); }
public PersonEntity(string name) : base(name) { this.m_personCarAssociation = new OneToOneAssociation<PersonEntity, CarEntity>( this, getOnRef: car => car.Driver, setOnRef: (car, person) => car.Driver = person, unsetOnRef: (car, person) => car.Driver = ReferenceEquals(car.Driver, person) ? null : car.Driver); this.m_personAddressesAssociation = new OneToManyAssociation<PersonEntity, AddressEntity>( root: this, added: newItem=> newItem.AddPerson(this), removed: oldItem=> oldItem.RemovePerson(this)); }
public CarEntity(string name) : base(name) { this.m_carDriverAssociation = new OneToOneAssociation<CarEntity, PersonEntity>( root: this, getOnRef: person => person.Car, setOnRef: (person, car) => person.Car = car, unsetOnRef: (persone, car) => persone.Car = ReferenceEquals(persone.Car, car) ? null : persone.Car); this.m_carGarageAssociation = new OneToOneAssociation<CarEntity, GarageEntity>( root: this, getOnRef: garage=> garage.HasCar(this) ? this : null, setOnRef: (garage, car)=> garage.AddCar(car), unsetOnRef: (garage, car) => garage.RemoveCar(car)); }
private static bool ClearAssociation(OneToOneAssociation property, NakedObject target) { Naked existingValue = property.get(target); if (existingValue != null) { if (existingValue is NakedObject) { property.clearAssociation(target, (NakedObject)existingValue); } else { ClearValue(property, target); } return(true); } return(false); }