//========================================================================= /// <summary> /// Returns a component that is a child of the paddock /// <param name="TypeToFind">The type to find. [Type.]ProxyClass</param> /// </summary> //========================================================================= public object LinkByType(String TypeToFind) { if (ApsimObjectsByType.ContainsKey(TypeToFind)) { return(ApsimObjectsByType[TypeToFind]); } else { Object foundObject = LinkField.FindApsimObject(TypeToFind, null, FQN, HostComponent); ApsimObjectsByType.Add(TypeToFind, foundObject); return(foundObject); } }
//========================================================================= /// <summary> /// Return a child component of the system by unqualified name. /// </summary> /// <param name="NameToFind">Unqualified name. Always relative to this component class. /// (if preceded by '.' then treat as in the root - for backwards compatability)</param> /// <returns>The object from the simulation - Either component or internal object</returns> //========================================================================= public object LinkByName(String NameToFind) { object E = null; if (ApsimIntObjectsByName.ContainsKey(NameToFind)) { E = ApsimIntObjectsByName[NameToFind]; //if already found } else { E = FindInternalEntity(NameToFind); if (E != null) { ApsimIntObjectsByName.Add(NameToFind, E); //keep this object for later searches } } if (E != null) { //internal entity if (E is Entity) { object Value = (E as Entity).Get(); return(Value); } else if (E is Instance) { object Value = (E as Instance).Model; return(Value); } return(null); } else { //external component if (ApsimObjectsByName.ContainsKey(NameToFind)) { return(ApsimObjectsByName[NameToFind]); //if already found } else { //ensure that the name triggers the search from the correct system String searchName = NameToFind; String sysName = FullName; if (searchName[0] == '.') { sysName = ""; //causes a search from the root (for backwards compatability) searchName = searchName.Remove(0, 1); if (searchName.LastIndexOf('.') > -1) //if this is a FQN search { sysName = searchName.Substring(0, searchName.LastIndexOf('.')); //search from the system in the name } } else //relative to this component { if (searchName.LastIndexOf('.') > -1) //if this name has any path preceding it { if (sysName.Length > 0) { sysName = sysName + '.'; } sysName = sysName + searchName.Substring(0, searchName.LastIndexOf('.')); //search from the system in the name } } Object foundObject = LinkField.FindApsimObject(null, searchName, sysName, HostComponent); ApsimObjectsByName.Add(NameToFind, foundObject); //keep this object for later searches return(foundObject); } } }