/// <summary> /// Recursively processes <see cref="ITable"/> instances to create <see cref="RowInstance"/> data for each table in the hierarchy. /// </summary> /// <param name="table"></param> void CreateInstances(ITable table, RowModelType type) { // Get the properties for the specified table columns var properties = table.Columns.Select(c => type.Properties[c.Name] as ModelValueProperty).ToArray(); // Verify all of the columns correlate to value properties if (properties.Any(p => p == null)) { throw new ArgumentException("The specified table columns do not match properties on the specified model type."); } // Create instances for each row in the table foreach (var row in table.Rows) { var instance = new RowInstance(type); var c = 0; foreach (var value in row) { instance.SetValue(properties[c++], value); } type.Instances.Add(instance.Id, instance); } // Recursively process child tables foreach (var child in table.Children) { CreateInstances(child, (RowModelType)((RowModelReferenceProperty)type.Properties[child.Name]).PropertyType); } }
protected override object GetInstance(string id) { // Get the existing instance if an identifer was specified if (id != null) { RowInstance instance; Instances.TryGetValue(id, out instance); if (instance == null) { Instances[id] = instance = new RowInstance(this); } return(instance); } // Otherwise, create a new instance else { return(new RowInstance(this)); } }