al momento sto usando ExpandoObject per memorizzare dinamicamente nome e cognome.È possibile creare una struttura ad albero dinamica usando ExpandoObject?
ad es.
// Create Expando object for testing
dynamic employee = new ExpandoObject();
// Dynamically add the fields to the expando
((IDictionary<String, Object>)employee).Add("FirstName", "John");
((IDictionary<String, Object>)employee).Add("Surname", "Smith");
Mi chiedevo se è possibile memorizzare in modo dinamico i campi in una struttura ad albero in modo che io possa avere il campo padre chiamato Nome, e poi due campi di bambini chiamati Nome e Cognome. Idealmente questo potrebbe potenzialmente essere espanso per includere più livelli secondari. Ho fatto un po 'di codice di psudo qui sotto per dimostrare idealmente come vorrei che funzionasse. (Naturalmente questo codice attualmente causa errori)
// Create Expando object for testing
dynamic employee = new ExpandoObject();
// Dynamically add the Name
((IDictionary<String, Object>)employee).Add("Name", "");
//Dynamically add the firstname and surname to employee.Name
((IDictionary<String, Object>)employee.Name).Add("FirstName", "John");
((IDictionary<String, Object>)employee.Name).Add("Surname", "Smith");
Expando? E 'un incantesimo di Harry Potter? +1 per la domanda interessante – sehe
@sehe, http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx –
@George: Sì, sono certificata da google dal 2003 – sehe