protected void OnSerialising(bool xmlSerialisation) { if (xmlSerialisation && Apsim.Ancestor <Replacements>(this) == null) { if (string.IsNullOrEmpty(ResourceName)) { if (!string.IsNullOrEmpty(Properties.Resources.ResourceManager.GetString(Name))) { ResourceName = Name; } else { return; } } SetNotVisible(this); allModels = new List <Model>(); allModels.AddRange(Children); List <Model> visibleModels = new List <Model>(); foreach (Model child in Children) { if (!child.IsHidden) { visibleModels.Add(child); } } Children = visibleModels; } }
/// <summary> /// We have just been deserialised. If from XML then load our model /// from resource. /// </summary> public override void OnCreated() { // lookup the resource get the xml and then deserialise to a model. if (!string.IsNullOrEmpty(ResourceName)) { var contents = ReflectionUtilities.GetResourceAsString(FullResourceName); if (contents != null) { Model modelFromResource = GetResourceModel(); modelFromResource.Enabled = Enabled; Children.RemoveAll(c => modelFromResource.Children.Contains(c, new ModelComparer())); Children.InsertRange(0, modelFromResource.Children); CopyPropertiesFrom(modelFromResource); // Make the model readonly if it's not under replacements. SetNotVisible(modelFromResource, Apsim.Ancestor <Replacements>(this) == null); Apsim.ParentAllChildren(this); } } }