Address address = new Address();
address.Country = "Chile";
address.City = "Santiago";
address.ZipCode = "43532";
//Factory instance creation object
//This is idea
Person person = new FactoryEntity<Person>().AssociateWithEntity(p=>p.Address, address);
public class Person: Entity
{
public string Name{ get; set; }
public string LastName{ get; set; }
public Address Address{ get; set; }
}
public class Address: Entity
{
public string Country{ get; set; }
public string City{ get; set; }
public string ZipCode{ get; set; }
}
public class FactoryEntity<TEntity> where TEntity : Entity
{
public void AssociateWithEntity<TProperty>(Expression<Func<TEntity, TProperty>> entityExpression, TProperty newValueEntity) where TProperty : Entity
{
if (instanceEntity == null || instanceEntity.IsTransient())
throw new ArgumentNullException();
/*TODO: Logic the association and validation
How set the newValueEntity into the property of entityExpression (x=>x.Direccion = direccion*/
}
}
Orada var olan 'propertyInfo' bir 'TProperty' değil, 'TEntity' içindir. Farklı türde bir nesne için bir özelliğe erişmek için kullanamazsınız. Dernek hangi yoldan gitmeli? Burada yapmaya çalıştığınız şey bana mantıklı gelmiyor. –
Çok buggy kodu ve ne istediğinizi söylemek kolay değil, açıklığa kavuşturun. –
Açıklama açık olmadığı için özür dilerim ama yapmak istediğim bir fabrika işgal etmek için izin veren bir fabrika işgal etmektir, bu nedenle düzgün bir şekilde –