Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public SensoryUnit(SensoryTypes senseType, string value, bool saveable = true)
 {
     Id    = -1;
     Type  = senseType;
     Value = value;
 }