Пример #1
0
        public override bool Parse(MSDFile.Value value)
        {
            // Only consider this line if it matches this property name.
            if (!ParseFirstParameter(value, out var rawStr))
            {
                return(false);
            }

            // Record the raw string to preserve formatting when writing.
            if (!string.IsNullOrEmpty(RawStringPropertyName))
            {
                Extras?.AddSourceExtra(RawStringPropertyName, rawStr);
            }

            if (!string.IsNullOrEmpty(rawStr))
            {
                var pairs = value.Params[1].Trim().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var pair in pairs)
                {
                    var kvp = pair.Split('=');
                    if (kvp.Length != 2)
                    {
                        Logger?.Warn($"{PropertyName}: Malformed pair '{pair}'. This value will be ignored.");
                        continue;
                    }

                    if (!double.TryParse(kvp[0], out var time))
                    {
                        Logger?.Warn($"{PropertyName}: Malformed value '{kvp[0]}'. Expected double. This value will be ignored.");
                        continue;
                    }

                    var valueStr = kvp[1];
                    if (valueStr.IndexOf(';') >= 0)
                    {
                        valueStr = valueStr.Substring(0, valueStr.IndexOf(';'));
                    }

                    T tValue;
                    try
                    {
                        tValue = (T)Convert.ChangeType(valueStr, typeof(T));
                    }
                    catch (Exception)
                    {
                        Logger?.Warn($"{PropertyName}: Failed to Convert '{valueStr}' to type '{typeof(T)}'.");
                        continue;
                    }

                    Values[time] = tValue;
                }
            }

            Extras?.AddSourceExtra(PropertyName, Values);

            return(true);
        }
Пример #2
0
        public override bool Parse(MSDFile.Value value)
        {
            // Only consider this line if it matches this property name.
            if (!DoesValueMatchProperty(value))
            {
                return(false);
            }

            List <T> parsedList = new List <T>();

            for (var paramIndex = 1; paramIndex < value.Params.Count; paramIndex++)
            {
                if (!string.IsNullOrEmpty(value.Params[paramIndex]))
                {
                    T tValue;
                    try
                    {
                        tValue = (T)Convert.ChangeType(value.Params[paramIndex], typeof(T));
                    }
                    catch (Exception)
                    {
                        Logger?.Warn($"{PropertyName}: Failed to Convert '{value.Params[paramIndex]}' to type '{typeof(T)}'.");
                        return(true);
                    }
                    parsedList.Add(tValue);
                }
            }

            Extras.AddSourceExtra(PropertyName, parsedList, true);
            return(true);
        }
Пример #3
0
        public override bool Parse(MSDFile.Value value)
        {
            // Only consider this line if it matches this property name.
            if (!ParseFirstParameter(value, out var valueStr))
            {
                return(false);
            }

            T tValue;

            try
            {
                tValue = (T)Convert.ChangeType(valueStr, typeof(T));
            }
            catch (Exception)
            {
                Logger?.Warn($"{PropertyName}: Failed to Convert '{valueStr}' to type '{typeof(T)}'.");
                return(true);
            }

            Extras.AddSourceExtra(PropertyName, tValue, true);
            return(true);
        }