मुझे पैटर्न फैक्ट्री विचार का उपयोग करके मेरी फैक्ट्रीएन्टिटीज क्लास में अभिव्यक्ति linq के साथ मेरी व्यक्तिगत श्रेणी इकाई में एक इकाई संपत्ति पता संबद्ध करने की आवश्यकता है, यह मेरे पास है और मैं यह करना चाहता हूं:एक संपत्ति चयनकर्ता अभिव्यक्ति का मूल्य कैसे निर्धारित करें <Func <T,TResult>>
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*/
}
}
आपके पास 'propertyInfo' है जो' TENTITY' के लिए है, न कि 'टीप्रोपर्टी'। आप किसी भिन्न प्रकार की ऑब्जेक्ट के लिए किसी प्रॉपर्टी तक पहुंचने के लिए इसका उपयोग नहीं कर सकते हैं। एसोसिएशन किस तरह से जाना जाता है? आप जो करने की कोशिश कर रहे हैं वह मुझे समझ में नहीं आता है। –
यह बहुत छोटी गाड़ी कोड है, और यह आसान नहीं है कि आप जो चाहते हैं उसे स्पष्ट करें। –
मुझे खेद है कि स्पष्टीकरण स्पष्ट नहीं था, लेकिन मैं ऐसा करना चाहता हूं जो एक फैक्ट्री पर कब्जा करने के लिए है जो मुझे ऑब्जेक्ट को एसोसिएशन को मान्य करने में हस्तक्षेप करने की अनुमति देता है, इसलिए यह उचित रूप से –