static public ISensoryUnit Parse(string text) { if (string.IsNullOrEmpty(text)) { return(null); } string parseText = text.Trim(); if (!parseText.StartsWith("{") || !parseText.EndsWith("}")) { return(null); } parseText = parseText.Substring(1, parseText.Length - 2); string[] splits = parseText.Split(new[] { '=' }); if (splits.Length != 2) { return(null); } SensoryTypes type = (SensoryTypes)Enum.Parse(typeof(SensoryTypes), splits[0].Trim(), true); string value = splits[1].Trim(); if (value.Length >= 2) { value = value.Substring(1, value.Length - 2); } else { value = string.Empty; } return(new SensoryUnit(type, value)); }
private ISensoryUnit GetOrCreateSensoryUnit(SensoryTypes senseType, string value) { ISensoryUnit result = new SensoryUnit(senseType, value, IS_SAVEABLE_UNIT); if (_kownSensoryUnits.Contains(result)) { result = _kownSensoryUnits[_kownSensoryUnits.IndexOf(result)]; } else { _kownSensoryUnits.Add(result); _kownSensoryUnits.Sort(); } return(result); }
public SensoryUnit(SensoryTypes senseType, string value, bool saveable = true) { Id = -1; Type = senseType; Value = value; }