public Boolean SystemSet(String systemName, out INametableItem systemItem) { // Find identifier IEnvironment context; Boolean Found = FindIdentifier(systemName, out context, out systemItem); if (Found && (context == this) && (systemItem.Identifierkind != IdentifierKind.UnitSystem)) { // Found locally but is not a system; Can't set as system return(false); } if (context == null) { context = this; } // Either identifier is a system in some context; set it to specified value // or identifier not found; No local identifier with that name, Declare local system systemItem = new NamedSystem(systemName); Physics.CurrentUnitSystems.Use((systemItem as NamedSystem).UnitSystem); return(context.SetLocalIdentifier(systemName, systemItem)); }
public Boolean UnitSet(IUnitSystem unitSystem, String unitName, Quantity unitValue, String unitSymbol, out INametableItem unitItem, out string errorMessage) { // Find identifier Boolean Found = FindIdentifier(unitName, out IEnvironment context, out unitItem); if (Found && (context == this) && (unitItem.Identifierkind != IdentifierKind.Unit)) { // Found locally, but is not a unit; Can't set as unit errorMessage = unitName + " is found locally but is not a unit; Can't set as unit"; return(false); } if (context == null) { context = this; } (bool OK, String errormessage)updateRes; if (unitItem == null) { // Either is identifier an unit in some context; set it to specified value // or identifier not found; No local identifier with that name, Declare local unit if (unitSystem == null) { if (unitValue != null && unitValue.Unit != null) { // Is same system as values unit unitSystem = unitValue.Unit.ExponentsSystem; } /** * if (unitSystem == null) * { // Is first unit in a new system * if (SystemSet(unitName + "_system", out INametableItem SystemItem)) * { * unitSystem = ((NamedSystem)SystemItem).UnitSystem; * } * } **/ } unitItem = new NamedUnit(unitSystem, unitName, unitSymbol, unitValue, this); updateRes = (true, ""); } else { NamedUnit nui = (NamedUnit)unitItem; updateRes = nui.UpdateUnit(unitName, unitValue); } errorMessage = updateRes.errormessage; if (!updateRes.OK) { return(false); } return(context.SetLocalIdentifier(unitName, unitItem)); }
public Boolean FindIdentifier(String identifierName, out IEnvironment foundInContext, out INametableItem item) { // Check local items Boolean Found = FindLocalIdentifier(identifierName, out item); if (Found) { foundInContext = this; return(true); } else // Check outher context if (OuterContext != null) { return(OuterContext.FindIdentifier(identifierName, out foundInContext, out item)); } foundInContext = null; return(false); }
// Check local items public Boolean FindLocalIdentifier(String identifierName, out INametableItem item) => NamedItems.GetItem(identifierName, out item);
// Update or add local item public Boolean SetLocalIdentifier(String identifierName, INametableItem item) => NamedItems.SetItem(identifierName, item);
public Boolean UnitSet(IUnitSystem unitSystem, String unitName, Quantity unitValue, out INametableItem unitItem) { // Find identifier IEnvironment context; Boolean Found = FindIdentifier(unitName, out context, out unitItem); if (Found && (context == this) && (unitItem.Identifierkind != IdentifierKind.Unit)) { // Found locally but is not a unit; Can't set as unit return(false); } if (context == null) { context = this; } // Either is identifier an unit in some context; set it to specified value // or identifier not found; No local identifier with that name, Declare local unit if (unitSystem == null) { if (unitValue != null && unitValue.Unit != null) { // Is same system as values unit unitSystem = unitValue.Unit.ExponentsSystem; } if (unitSystem == null) { // Is first unit in a new system INametableItem SystemItem; if (SystemSet(unitName + "_system", out SystemItem)) { unitSystem = ((NamedSystem)SystemItem).UnitSystem; } } } unitItem = new NamedUnit(unitSystem, unitName, unitValue, this); return(context.SetLocalIdentifier(unitName, unitItem)); }